dplassgit / d2lang

D2 is a strongly-typed, statically-typed, (mostly) inferred-type compiled language.
MIT License
6 stars 1 forks source link

NPE is not always detected. #256

Closed dplassgit closed 10 months ago

dplassgit commented 1 year ago
rt:record{i:int}

a=new rt
a=null
print a.i

On the last line, instead of a compile or runtime NPE, it throws UnsupportedOperation error: Null pointer error which is from https://github.com/dplassgit/d2lang/blob/db8e8d0069856e247968769c16dc923f2178c973/src/com/plasstech/lang/d2/codegen/x64/NasmCodeGenerator.java#L509

dplassgit commented 1 year ago

This happens because constant propagation propagates the null to the a.i expression but the code generator just throws an exception at compile time instead of generating a runtime message (or a proper compile-time message.)