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

[Bug]: Ambiguous compiler error when instantiating a class that does not exist #42705

Open
hasathcharu opened this issue May 8, 2024 · 0 comments · May be fixed by #42756
Open

[Bug]: Ambiguous compiler error when instantiating a class that does not exist #42705

hasathcharu opened this issue May 8, 2024 · 0 comments · May be fixed by #42756
Assignees
Labels
Area/CodeAnalysis Data flow , Code and Closure analysis related issues #Compiler Crash All issues caused by NPE, CCE, etc Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation

Comments

@hasathcharu
Copy link

Description

When a class is instantiated with the new keyword, if you give a class that does not exist, the thrown compiler error is vague and causes a Bad Sad error. The project folder has a red dot marked on VS Code without an indication as to which file the error is stemming from. The resulting compiler error also points to the first line, first column of the bal file.

  • VS Code Screen
    Here, note that the class db does not exist.

image

  • Console Error Log
[2024-05-08 11:54:37,574] SEVERE {b7a.log.crash} - Cannot read field "flags" because "type.tsymbol" is null 
java.lang.NullPointerException: Cannot read field "flags" because "type.tsymbol" is null
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:2809)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:286)
        at org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit.accept(BLangTypeInit.java:70)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyzeExpr(CodeAnalyzer.java:3605)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:3296)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:286)
        at org.wso2.ballerinalang.compiler.tree.expressions.BLangCheckedExpr.accept(BLangCheckedExpr.java:70)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyzeExpr(CodeAnalyzer.java:3605)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:1838)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:286)
        at org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment.accept(BLangAssignment.java:86)
        at org.wso2.ballerinalang.compiler.tree.SimpleBLangNodeAnalyzer.visitNode(SimpleBLangNodeAnalyzer.java:217)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyzeNode(CodeAnalyzer.java:355)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:544)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:286)
        at org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody.accept(BLangBlockFunctionBody.java:65)
        at org.wso2.ballerinalang.compiler.tree.SimpleBLangNodeAnalyzer.visitNode(SimpleBLangNodeAnalyzer.java:217)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyzeNode(CodeAnalyzer.java:355)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visitFunction(CodeAnalyzer.java:519)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:462)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:286)
        at org.wso2.ballerinalang.compiler.tree.BLangFunction.accept(BLangFunction.java:82)
        at org.wso2.ballerinalang.compiler.tree.SimpleBLangNodeAnalyzer.visitNode(SimpleBLangNodeAnalyzer.java:217)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyzeNode(CodeAnalyzer.java:355)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyzeTopLevelNodes(CodeAnalyzer.java:344)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:332)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.visit(CodeAnalyzer.java:286)
        at org.wso2.ballerinalang.compiler.tree.BLangPackage.accept(BLangPackage.java:172)
        at org.wso2.ballerinalang.compiler.tree.SimpleBLangNodeAnalyzer.visitNode(SimpleBLangNodeAnalyzer.java:217)
        at org.wso2.ballerinalang.compiler.semantics.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:320)
        at io.ballerina.projects.internal.CompilerPhaseRunner.codeAnalyze(CompilerPhaseRunner.java:192)
        at io.ballerina.projects.internal.CompilerPhaseRunner.performTypeCheckPhases(CompilerPhaseRunner.java:115)
        at io.ballerina.projects.ModuleContext.compileInternal(ModuleContext.java:435)
        at io.ballerina.projects.ModuleCompilationState$1.compile(ModuleCompilationState.java:45)
        at io.ballerina.projects.ModuleContext.compile(ModuleContext.java:383)
        at io.ballerina.projects.PackageCompilation.compileModulesInternal(PackageCompilation.java:211)
        at io.ballerina.projects.PackageCompilation.compileModules(PackageCompilation.java:195)
        at io.ballerina.projects.PackageCompilation.compile(PackageCompilation.java:102)
        at io.ballerina.projects.PackageCompilation.from(PackageCompilation.java:97)
        at io.ballerina.projects.PackageContext.getPackageCompilation(PackageContext.java:244)
        at io.ballerina.projects.Package.getCompilation(Package.java:150)
        at io.ballerina.projects.Package.runCodeGeneratorPlugins(Package.java:323)
        at io.ballerina.cli.task.CompileTask.execute(CompileTask.java:153)
        at io.ballerina.cli.TaskExecutor.executeTasks(TaskExecutor.java:40)
        at io.ballerina.cli.cmd.RunCommand.execute(RunCommand.java:258)
        at java.base/java.util.Optional.ifPresent(Optional.java:178)
        at io.ballerina.cli.launcher.Main.main(Main.java:58)
 
ERROR [proj:(1:1,1:1)] Compilation failed due to: Cannot read field "flags" because "type.tsymbol" is null
error: compilation contains errors

Steps to Reproduce

  • Create a new ballerina project
  • Instantiate a class that does not exist
public function main() returns error? {
    _ = check new db ();
}

Affected Version(s)

Ballerina Swan Lake Update 09

OS, DB, other environment details and versions

OS: Ubuntu 22.04.4 LTS
VS Code Version: 1.88.1
Ballerina VS Code Extension: v4.6.0

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 8, 2024
@lochana-chathura lochana-chathura added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Crash All issues caused by NPE, CCE, etc and removed needTriage The issue has to be inspected and labeled manually labels May 9, 2024
@nipunayf nipunayf added the Area/CodeAnalysis Data flow , Code and Closure analysis related issues #Compiler label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/CodeAnalysis Data flow , Code and Closure analysis related issues #Compiler Crash All issues caused by NPE, CCE, etc Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
Status: PR Sent
Development

Successfully merging a pull request may close this issue.

4 participants