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

Compiler crashes when a union is used within multiple wait #34821

Closed
IMS94 opened this issue Jan 25, 2022 · 1 comment · Fixed by #37832
Closed

Compiler crashes when a union is used within multiple wait #34821

IMS94 opened this issue Jan 25, 2022 · 1 comment · Fixed by #37832
Assignees
Labels
Area/Compiler Fix/Crash All issues caused by NPE, CCE, etc Points/2 Equivalent to two days effort Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@IMS94
Copy link
Contributor

IMS94 commented Jan 25, 2022

Description:
Consider the below code.

import ballerina/log;

type WaitResult record {|
    boolean|error producer;
    boolean consumer;
|};

public function main() {
    log:printInfo("initializing app...");

    // Producer 1
    worker Producer1 returns boolean|error {
        int i = 100;
        i -> Consumer;
        error? unionResult = flush Consumer;
        log:printInfo("Sent item", i = i);
        return true;
    }

    worker Producer2 returns boolean|error {
        int i = 100;
        i -> Consumer;
        error? unionResult = flush Consumer;
        log:printInfo("Sent item", i = i);
        return true;
    }

    // Consumer
    worker Consumer returns boolean {
        int i = <- Producer;
        log:printInfo("Received item", i = i);
        return false;
    }

    WaitResult res = wait {producer: Producer1|Producer2, consumer: Consumer};
    log:printInfo("Worker execution finished", result = res);
}

Note the syntactically incorrect line WaitResult res = wait {producer: Producer1|Producer2, consumer: Consumer};. When compiled, this gives the following crash log:

ballerina: Oh no, something really went wrong. Bad. Sad.

We appreciate it if you can report the code that broke Ballerina in
https://github.com/ballerina-platform/ballerina-lang/issues with the
log you get below and your sample code.

We thank you for helping make us better.

[2022-01-25 13:39:10,008] SEVERE {b7a.log.crash} - class org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType cannot be cast to class org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType and org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType are in unnamed module of loader 'app') 
java.lang.ClassCastException: class org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType cannot be cast to class org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType (org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType and org.wso2.ballerinalang.compiler.semantics.model.types.BFutureType are in unnamed module of loader 'app')
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.setEventualTypeForExpression(TypeChecker.java:4095)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.checkWaitKeyValExpr(TypeChecker.java:4083)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.checkTypesForRecords(TypeChecker.java:4044)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.setResultTypeForWaitForAllExpr(TypeChecker.java:3935)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.setResultTypeForWaitForAllExpr(TypeChecker.java:3960)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.visit(TypeChecker.java:3924)
	at org.wso2.ballerinalang.compiler.tree.expressions.BLangWaitForAllExpr.accept(BLangWaitForAllExpr.java:52)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.checkExpr(TypeChecker.java:380)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.TypeChecker.checkExpr(TypeChecker.java:354)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.visit(SemanticAnalyzer.java:1052)
	at org.wso2.ballerinalang.compiler.tree.BLangSimpleVariable.accept(BLangSimpleVariable.java:54)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4057)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4028)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeDef(SemanticAnalyzer.java:4020)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.visit(SemanticAnalyzer.java:1907)
	at org.wso2.ballerinalang.compiler.tree.statements.BLangSimpleVariableDef.accept(BLangSimpleVariableDef.java:50)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4057)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4028)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeStmt(SemanticAnalyzer.java:4024)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.visit(SemanticAnalyzer.java:524)
	at org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody.accept(BLangBlockFunctionBody.java:60)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4057)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.visit(SemanticAnalyzer.java:500)
	at org.wso2.ballerinalang.compiler.tree.BLangFunction.accept(BLangFunction.java:76)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4057)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeNode(SemanticAnalyzer.java:4028)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyzeDef(SemanticAnalyzer.java:4020)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.visit(SemanticAnalyzer.java:349)
	at org.wso2.ballerinalang.compiler.tree.BLangPackage.accept(BLangPackage.java:167)
	at org.wso2.ballerinalang.compiler.semantics.analyzer.SemanticAnalyzer.analyze(SemanticAnalyzer.java:309)
	at io.ballerina.projects.internal.CompilerPhaseRunner.typeCheck(CompilerPhaseRunner.java:188)
	at io.ballerina.projects.internal.CompilerPhaseRunner.performTypeCheckPhases(CompilerPhaseRunner.java:114)
	at io.ballerina.projects.ModuleContext.compileInternal(ModuleContext.java:436)
	at io.ballerina.projects.ModuleCompilationState$1.compile(ModuleCompilationState.java:45)
	at io.ballerina.projects.ModuleContext.compile(ModuleContext.java:386)
	at io.ballerina.projects.PackageCompilation.compileModulesInternal(PackageCompilation.java:213)
	at io.ballerina.projects.PackageCompilation.compileModules(PackageCompilation.java:198)
	at io.ballerina.projects.PackageCompilation.compile(PackageCompilation.java:114)
	at io.ballerina.projects.PackageCompilation.from(PackageCompilation.java:103)
	at io.ballerina.projects.PackageContext.getPackageCompilation(PackageContext.java:214)
	at io.ballerina.projects.Package.getCompilation(Package.java:141)
	at org.ballerinalang.langserver.workspace.BallerinaWorkspaceManager.waitAndGetPackageCompilation(BallerinaWorkspaceManager.java:271)
	at org.ballerinalang.langserver.util.LSClientUtil.chekAndRegisterCommands(LSClientUtil.java:78)
	at org.ballerinalang.langserver.BallerinaTextDocumentService.didChange(BallerinaTextDocumentService.java:556)
	at jdk.internal.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:152)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:220)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:187)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
	at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Steps to reproduce:
See description

Affected Versions:
SL 2201 RC2

@IMS94 IMS94 added Type/Bug Area/Compiler Fix/Crash All issues caused by NPE, CCE, etc Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. GA-Test-Hackathon labels Jan 25, 2022
@gimantha gimantha added the Points/2 Equivalent to two days effort label Sep 7, 2022
@github-actions
Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@pcnfernando pcnfernando added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Compiler Fix/Crash All issues caused by NPE, CCE, etc Points/2 Equivalent to two days effort Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
No open projects
Status: No status
4 participants