RuntimeType is not public!

Description

Because the type RuntimeType is not public, when constants of this type, such as System.Int64 encountered in Clojure source code, are not recognized as being typed, and hence have an inferred type of the default System.Object , leading to unnecessary reflection warnings.

An example is:

(System.Array/CreateInstance Int64 (int 5))

The Int64 will not be seen as being of type System.Type and we will not be able to resolve the call.

In the compiler, the Int64 becomes a ConstantExpr in the AST. The current definition of ConstantExpr.HasClrType is just _v.GetType().IsPublic where _v is the constant in question. When you call GetType on something like System.Int64, you get back System.RuntimeType, which is not public. Hence, this constant is seen to have no defined type and hence is defaultly taken as a System.Object.

This is typically on a problem when calling .GetType() on a System.Type value. Special casing this in ConstExpr.HasClrType and ConstExpr.ClrType will take care of this.

Environment

None

Activity

Show:

David MillerNovember 30, 2022 at 1:03 AM

Introduced special handling for values of type Type in ConstExpr.HasClrType and ConstExpr.ClrType.
Commit 99179111, 2022.11.29

Fixed

Details

Assignee

Reporter

Priority

Created November 29, 2022 at 11:06 PM
Updated November 30, 2022 at 1:03 AM
Resolved November 30, 2022 at 1:03 AM

Flag notifications