Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2201.9.x] Fix getting non-accessible symbol error for error intersections with details #42925

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5690,8 +5690,8 @@ private BErrorType createErrorType(BType lhsType, BType rhsType, BType detailTyp
BErrorType lhsErrorType = (BErrorType) lhsType;
BErrorType rhsErrorType = (BErrorType) rhsType;

BErrorType errorType = createErrorType(detailType, lhsType.flags, env);
errorType.tsymbol.flags |= rhsType.flags;
long flags = lhsType.flags | rhsType.flags | Flags.PUBLIC; // Anonymous (generated) types are marked as public.
BErrorType errorType = createErrorType(detailType, flags, env);

errorType.typeIdSet = BTypeIdSet.getIntersection(lhsErrorType.typeIdSet, rhsErrorType.typeIdSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ public void testUnsupportedIntersectionNegative() {
assertEquals(result.getErrorCount(), index);
}

@Test
public void testErrorIntersectionAccessTest() {
CompileResult result = BCompileUtil.compile("test-src/types/intersection/error-intersection-access");
assertEquals(result.getErrorCount(), 0);
BRunUtil.invoke(result, "testErrorIntersectionFromImportedModule");
}

@AfterClass
public void tearDown() {
readOnlyIntersectionResults = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "testorg"
name = "error_intersection_access"
version = "0.1.0"

[build-options]
observabilityIncluded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import error_intersection_access.error_intersection_mod as err_lib;

const MESSAGE = "Message";

public function testErrorIntersectionFromImportedModule() {
err_lib:RemoteServerError remoteServerErr = error err_lib:RemoteServerError(MESSAGE);
assertError(remoteServerErr);

err_lib:ApplicationResponseError applResponeErr = error err_lib:ApplicationResponseError(MESSAGE);
assertError(applResponeErr);

err_lib:ClientRequestErrorWithStatusCode clientReqErrWithStatusCode = error (MESSAGE, code = 404);
assertError(clientReqErrWithStatusCode, 404);

err_lib:ApplicationResponseErrorWithStatusCode appRespErrWithStatusCode = error (MESSAGE, code = 401);
assertError(appRespErrWithStatusCode, 401);

err_lib:BadRequestError badReqErr = error err_lib:BadRequestError(MESSAGE, code = 400);
assertError(badReqErr, 400);

err_lib:Error err = error err_lib:Error(MESSAGE);
assertError(err);
}

function assertError(any|error actual, int? code = ()) {
if actual !is error {
panic error(string `expected an error, found '${actual.toString()}'`);
}

if MESSAGE != actual.message() {
panic error(string `expected message: '${MESSAGE}', found: '${actual.message()}'`);
}

if code != () {
var detail = <record {|int code;|} & readonly> actual.detail();
if code != detail.code {
panic error(string `expected code: '${code}', found: '${detail.code}'`);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

public type Status record {
int code;
};

public type Error distinct error;

public type ClientRequestError distinct Error & error;

public type RemoteServerError distinct error & error;

public type ApplicationResponseError distinct ClientRequestError & RemoteServerError;

public type ApplicationResponseErrorWithStatusCode distinct ApplicationResponseError & error<Status>;

public type ClientRequestErrorWithStatusCode distinct ClientRequestError & error<Status>;

public type BadRequestError distinct ApplicationResponseErrorWithStatusCode & ClientRequestErrorWithStatusCode;
Loading