Skip to content

Commit

Permalink
Merge pull request #41454 from gabilang/fix-abst-stat-interop
Browse files Browse the repository at this point in the history
Provide proper compilation errors for invalid interop usages
  • Loading branch information
gabilang authored Oct 27, 2023
2 parents 8ac9786 + 5b94cf5 commit 8eed597
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ JMethod resolve(JMethodRequest jMethodRequest) {
if (jMethods.isEmpty()) {
if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) {
throw new JInteropException(DiagnosticErrorCode.CONSTRUCTOR_NOT_FOUND,
"No such public constructor found in class '" + jMethodRequest.declaringClass + "'");
"No such public constructor found in class '" + jMethodRequest.declaringClass.getName() + "'");
} else {
throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND,
"No such public method '" + jMethodRequest.methodName + "' found in class '" +
jMethodRequest.declaringClass + "'");
jMethodRequest.declaringClass.getName() + "'");
}
}

Expand Down Expand Up @@ -399,15 +399,8 @@ private void validateArgumentTypes(JMethodRequest jMethodRequest, JMethod jMetho
receiverIndex = jMethodRequest.pathParamCount;
}
BType receiverType = bParamTypes[receiverIndex];
boolean isLastParam = (bParamTypes.length - jMethodRequest.pathParamCount) == 1;
if (!isValidParamBType(jMethodRequest.declaringClass, receiverType, isLastParam,
jMethodRequest.restParamExist)) {
if (jParamTypes.length == 0 || bParamTypes[0].tag != TypeTags.HANDLE) {
throwMethodNotFoundError(jMethodRequest);
} else {
throwNoSuchMethodError(jMethodRequest.methodName, jParamTypes[0], receiverType,
jMethodRequest.declaringClass);
}
if (receiverType.tag != TypeTags.HANDLE) {
throwMethodNotFoundError(jMethodRequest);
}
for (int k = receiverIndex; k < bParamTypes.length - 1; k++) {
bParamTypes[k] = bParamTypes[k + 1];
Expand Down Expand Up @@ -854,12 +847,12 @@ private JMethod resolveMatchingMethod(JMethodRequest jMethodRequest, List<JMetho
if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) {
throw new JInteropException(DiagnosticErrorCode.CONSTRUCTOR_NOT_FOUND,
"No such public constructor that matches with parameter types '" + paramTypesSig +
"' found in class '" + jMethodRequest.declaringClass + "'");
"' found in class '" + jMethodRequest.declaringClass.getName() + "'");
} else {
throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND,
"No such public method '" + jMethodRequest.methodName + "' that matches with parameter types " +
"'" +
paramTypesSig + "' found in class '" + jMethodRequest.declaringClass + "'");
"'" + paramTypesSig + "' found in class '" + jMethodRequest.declaringClass.getName() +
"'");
}
} else if (resolvedJMethods.size() > 1) {
if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) {
Expand Down Expand Up @@ -983,18 +976,18 @@ private void throwMethodNotFoundError(JMethodRequest jMethodRequest) throws JInt
if (jMethodRequest.kind == JMethodKind.CONSTRUCTOR) {
throw new JInteropException(DiagnosticErrorCode.CONSTRUCTOR_NOT_FOUND,
"No such public constructor with '" + jMethodRequest.bFuncParamCount +
"' parameter(s) found in class '" + jMethodRequest.declaringClass + "'");
"' parameter(s) found in class '" + jMethodRequest.declaringClass.getName() + "'");
} else {
if (jMethodRequest.bFuncParamCount == 0 || jMethodRequest.bParamTypes[0].tag != TypeTags.HANDLE) {
throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND,
"No such public static method '" + jMethodRequest.methodName + "' with '" +
jMethodRequest.bFuncParamCount +
"' parameter(s) found in class '" + jMethodRequest.declaringClass + "'");
"' parameter(s) found in class '" + jMethodRequest.declaringClass.getName() + "'");
} else {
throw new JInteropException(DiagnosticErrorCode.METHOD_NOT_FOUND,
"No such public method '" + jMethodRequest.methodName + "' with '" +
jMethodRequest.bFuncParamCount +
"' parameter(s) found in class '" + jMethodRequest.declaringClass + "'");
"' parameter(s) found in class '" + jMethodRequest.declaringClass.getName() + "'");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
*
* 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.
*/
package org.ballerinalang.nativeimpl.jvm.tests;

/**
* This class is used for Java interoperability tests.
*
* @since 2201.9.0
*/
public class ClassWithPrivateConstructor {

private ClassWithPrivateConstructor() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -816,4 +816,12 @@ public static void getMapValueWithBalEnv(Environment env, BString name, long age
output.put(StringUtils.fromString("results"), results);
balFuture.complete(output);
}

public static BString testOverloadedMethods(Environment env, BArray arr, BString str) {
return str;
}

public static BString testOverloadedMethods(ArrayValue obj, BString str) {
return str;
}
}
Loading

0 comments on commit 8eed597

Please sign in to comment.