Skip to content

Commit

Permalink
Merge pull request #42876 from dulajdilshan/fix-42806
Browse files Browse the repository at this point in the history
Fix getting non-accessible symbol error for error intersections with details
  • Loading branch information
dulajdilshan authored Jul 1, 2024
2 parents 6f22bc8 + 6eed512 commit af69b2f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5685,8 +5685,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;

0 comments on commit af69b2f

Please sign in to comment.