HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.18k stars 656 forks source link

Uncaught exception Cannot call null (reproducible!) #9175

Open nadako opened 4 years ago

nadako commented 4 years ago

So far I failed to reproduce this outside VSCode, but it is 100% reproducible inside it. Might have something to do with --cwd calls because of the weird changed directories: [] below.

Main.hx

class Main {
    static function main() {
        Macro.func(); 
    }
}

Macro.hx

class Macro {
    public static macro function func() {
        var t = haxe.macro.Context.getType("Int");
        trace(t);
        return macro 1;
    }
}

build.hxml

-main Main
-js main.js

.vscode/settings.json

{
    "haxe.displayServer": {"arguments": ["-v"]},
    "haxe.buildCompletionCache": false,
    "haxe.enableDiagnostics": false
}

(so the amount of uncontrolled server calls is minimal)

1) Open this project in VSCode 2) Compile with the build task (so cache server is used) 3) Comment line 3 in Macro.hx (var t = haxe.macro.Context.getType("Int");) and save the file 4) Compile with the build task again - get the proper error (Unknown identifier : t) 5) Uncomment line 3 in Macro.hx back and save the file 6) Compile with the build task - BAM: Macro.hx:3: characters 17-50 : Uncaught exception Cannot call null

Haxe server output ``` Haxe language server started Using --server-connect Haxe connected! Processing Arguments [--display,{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"supportsResolve":true,"exclude":["zpp_nape"],"maxCompletionItems":1000}}] Completion Response = {"jsonrpc":"2.0","id":0,"result":{"result":{"methods":["display/definition","server/contexts","server/moduleCreated","server/invalidate","server/module","server/files","initialize","display/completion","typer/compiledTypes","display/references","server/modules","server/memory/context","display/completionItem/resolve","display/typeDefinition","server/memory","display/implementation","display/hover","display/package","display/signatureHelp","server/memory/module","server/readClassPaths","server/configure"],"haxeVersion":{"major":4,"minor":1,"patch":0,"pre":"rc.1","build":"bc6eca1fd"},"protocolVersion":{"major":0,"minor":4,"patch":0}},"timestamp":1582399821.6802447}} Stats = 0 files, 0 classes, 0 methods, 0 macros Time spent : 0.000s Listening on port 6000 Processing Arguments [--display,{"jsonrpc":"2.0","id":1,"method":"server/configure","params":{"noModuleChecks":true,"print":{"completion":false,"reusing":false},"legacyCompletion":false}}] Stats = 0 files, 0 classes, 0 methods, 0 macros Time spent : 0.000s Client connected Processing Arguments [--cwd,c:\Users\nadako\Code\playground,build.hxml] Defines dce=std,haxe3=1,haxe4=1,haxe=4.1.0-rc.1,haxe_ver=4.100,js-es5=1,js=1,js_es5=1,js_es=5,source-header=Generated by Haxe 4.1.0-rc.1+bc6eca1fd,target.name=js,target.unicode=true,target.utf16=true,true=1,utf16=1 Using signature 84fef1af5de52a14c9c1eb15ad163b2e Display position: ?: -1--1 0, js: Cached 48 modules Stats = 158 files, 171 classes, 862 methods, 1 macros Time spent : 0.150s Client disconnected Processing Arguments [--display,{"jsonrpc":"2.0","id":2,"method":"server/invalidate","params":{"file":"c:/Users/nadako/Code/playground/Macro.hx"}}] Stats = 0 files, 0 classes, 0 methods, 0 macros Time spent : 0.000s Client connected Processing Arguments [--cwd,c:\Users\nadako\Code\playground,build.hxml] Defines dce=std,haxe3=1,haxe4=1,haxe=4.1.0-rc.1,haxe_ver=4.100,js-es5=1,js=1,js_es5=1,js_es=5,source-header=Generated by Haxe 4.1.0-rc.1+bc6eca1fd,target.name=js,target.unicode=true,target.utf16=true,true=1,utf16=1 Using signature 84fef1af5de52a14c9c1eb15ad163b2e Display position: ?: -1--1 0, js: skipping Main(Macro) 0, js: skipping Macro 1,evl: skipping Macro > Macro.hx:4: characters 15-16 : Unknown identifier : t Macro.hx:4: characters 15-16 : For function argument 'v' 1,evl: found 35 directories 0, js: found 41 directories Stats = 2 files, 3 classes, 2 methods, 1 macros Time spent : 0.030s Client disconnected Processing Arguments [--display,{"jsonrpc":"2.0","id":3,"method":"server/invalidate","params":{"file":"c:/Users/nadako/Code/playground/Macro.hx"}}] Stats = 0 files, 0 classes, 0 methods, 0 macros Time spent : 0.000s Client connected Processing Arguments [--cwd,c:\Users\nadako\Code\playground,build.hxml] Defines dce=std,haxe3=1,haxe4=1,haxe=4.1.0-rc.1,haxe_ver=4.100,js-es5=1,js=1,js_es5=1,js_es=5,source-header=Generated by Haxe 4.1.0-rc.1+bc6eca1fd,target.name=js,target.unicode=true,target.utf16=true,true=1,utf16=1 Using signature 84fef1af5de52a14c9c1eb15ad163b2e Display position: ?: -1--1 0, js: changed directories: [] 0, js: skipping Main(Macro) 0, js: skipping Macro 1,evl: changed directories: [] 1,evl: skipping Macro > Macro.hx:3: characters 17-50 : Uncaught exception Cannot call null Main.hx:3: characters 3-15 : Called from here > Main.hx:1: lines 1-5 : Defined in this class Stats = 2 files, 3 classes, 2 methods, 1 macros Client disconnected Time spent : 0.005s ```

As mentioned, these changed directories: [] look suspicious and if it is the cause, it might explain why it's so hard to reproduce as it might be related to current working directories.

Gama11 commented 4 years ago

This only seems to happen with --server-connect, which explains why simn bisected this to 1528b81b0990779b15ecee41227b19e6d29066dc - haxe-language-server only enables that if the haxe version is >= 4.1.

RealyUniqueName commented 4 years ago

Yeah, I can't reproduce this with --wait even repeating exact same commands and file modifications vshaxe does.

RealyUniqueName commented 4 years ago

Btw, that cannot call null comes from haxe.macro.Context static prototype being used without its fields populated.

Simn commented 4 years ago

Yes, I already investigated that a bit and found that the cf_expr values were all None. This suggests some problem in the compilation server, not something eval-specific.

RealyUniqueName commented 4 years ago

Provided sample works fine now.

nadako commented 4 years ago

FYI I still get this when working on macros sometimes, but it's much rarer after the fix! I'll try to provide an example next time I get it.

zommerfelds commented 2 years ago

Had the same issue today in vscode when working on macros. Restarting the language server fixed the issue, so can't repro anymore.