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

[FIX] Compiler plugin crashes when using a new-expr with a user-defined class in the same source #495

Merged
merged 6 commits into from
Mar 29, 2022
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
4 changes: 2 additions & 2 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "websubhub"
version = "1.2.1"
version = "1.2.2"
authors = ["Ballerina"]
keywords = ["websub", "hub", "publisher", "service", "listener", "client"]
repository = "https://github.com/ballerina-platform/module-ballerina-websubhub"
Expand All @@ -10,4 +10,4 @@ license = ["Apache-2.0"]
distribution = "2201.0.1"

[[platform.java11.dependency]]
path = "../native/build/libs/websubhub-native-1.2.1.jar"
path = "../native/build/libs/websubhub-native-1.2.2-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "websubhub-compiler-plugin"
class = "io.ballerina.stdlib.websubhub.WebSubHubCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/websubhub-compiler-plugin-1.2.1.jar"
path = "../compiler-plugin/build/libs/websubhub-compiler-plugin-1.2.2-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ modules = [
[[package]]
org = "ballerina"
name = "websubhub"
version = "1.2.1"
version = "1.2.2"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "http"},
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- [Compiler plugin crashes when using a new-expr with a user-defined class in the same source](https://github.com/ballerina-platform/ballerina-standard-library/issues/2815)

## [1.2.0] - 2022-01-29

### Added
- [WebSub/WebSubHub should support `readonly` parameters for remote methods](https://github.com/ballerina-platform/ballerina-standard-library/issues/2604)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ public void testInvalidReadonlyParams() {
invalidTypeDesc, "onUnsubscription");
}

@Test
public void testWithNexExprWithUserDefinedClasses() {
Package currentPackage = loadPackage("sample_21");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
Assert.assertEquals(diagnosticResult.errorCount(), 0);
}

private void validateErrorsForInvalidReadonlyTypes(WebSubHubDiagnosticCodes expectedCode, Diagnostic diagnostic,
String typeDesc, String remoteMethodName) {
DiagnosticInfo info = diagnostic.diagnosticInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "websubhub_test"
name = "sample_21"
version = "0.1.0"

[build-options]
observabilityIncluded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2022 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. 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 ballerina/websubhub as _;

class Foo {
}

public function main() {
_ = new Foo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void perform(SyntaxNodeAnalysisContext context) {
SyntaxKind nodeSyntaxKind = node.kind();
if (nodeSyntaxKind == SyntaxKind.EXPLICIT_NEW_EXPRESSION) {
ExplicitNewExpressionNode expressionNode = (ExplicitNewExpressionNode) node;
if (!(expressionNode.typeDescriptor().kind() == SyntaxKind.QUALIFIED_NAME_REFERENCE)) {
return;
}
QualifiedNameReferenceNode nameRef = (QualifiedNameReferenceNode) expressionNode.typeDescriptor();
Optional<Symbol> symbolOpt = context.semanticModel().symbol(nameRef);
if (symbolOpt.isPresent() && symbolOpt.get() instanceof TypeReferenceTypeSymbol) {
Expand All @@ -72,6 +75,9 @@ public void perform(SyntaxNodeAnalysisContext context) {
ListenerDeclarationNode parentNode = (ListenerDeclarationNode) expressionNode.parent();
Optional<TypeDescriptorNode> parentTypeOpt = parentNode.typeDescriptor();
if (parentTypeOpt.isPresent()) {
if (!(parentTypeOpt.get().kind() == SyntaxKind.QUALIFIED_NAME_REFERENCE)) {
return;
}
QualifiedNameReferenceNode parentType = (QualifiedNameReferenceNode) parentTypeOpt.get();
Optional<Symbol> parentSymbolOpt = context.semanticModel().symbol(parentType);
if (parentSymbolOpt.isPresent() && parentSymbolOpt.get() instanceof TypeReferenceTypeSymbol) {
Expand Down