odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.13k stars 551 forks source link

error on type_of(value of untyped type) #3867

Closed karl-zylinski closed 3 days ago

karl-zylinski commented 3 days ago

Doing type_of(nil) or type_of(5) now gives a proper error instead of tripping an internal assertion.

This fixes #1180 since bug := typeid_of(type_of(nil)) cannot get past the type_of part anymore.

Old behavior

type_of(nil) gives:

C:\Odin\src\types.cpp(3677): Assertion Failure: `is_type_typed(t)` untyped nil

type_of(5) gives:

C:\Odin\src\types.cpp(3677): Assertion Failure: `is_type_typed(t)` untyped integer

New behavior

type_of(nil) =>

C:/bug_repros/typeid_bug/typeid_bug.odin(6:27) Error: 'type_of' of untyped nil cannot be determined 
    bug := typeid_of(type_of(nil)) 
                             ^~^ 

type_of(5) =>

C:/bug_repros/typeid_bug/typeid_bug.odin(7:28) Error: 'type_of' of untyped integer cannot be determined 
    bug2 := typeid_of(type_of(5)) 
                              ^