IntelliJ-Luanalysis
IntelliJ-Luanalysis copied to clipboard
Top and Bottom Types Distinct from "any"
I hope I'm understanding the current intended semantics of any
correctly. To my understanding, any
is a type that is meant to be assignable to any other type and also from any other type. It is used in places where the real type isn't known or where it would be too cumbersome to write it down. Similar to any
in TypeScript and Any
in Python.
What I'm mainly missing is a Top type, i.e. a type that is assignable from any other type, but not vice-versa. This would be useful in cases where the type a type is not known and where the analyzer should check that every possible type is handled. This is what Python's object
and TypeScript's unknown
is.
And by extension, a Bottom type could be added, i.e. a type that is assignable to any other type, but not vice-versa. This would be useful in cases that are expected to never happen, e.g. as return type of a function that never returns or that always panics. This is what Python's Never
(alias of NoReturn
) and TypeScript's never
is.