Correctly type check Class<T>#1698
Conversation
7c64e69 to
5adcbf7
Compare
c2f4029 to
d31129f
Compare
17b645c to
bfb8210
Compare
096cb0d to
acd6e0a
Compare
|
General comment: given this: typealias MyNumber = Number
foo: Class<MyNumber> = NumberThis seems like an incorrect error, because Might also be okay to not throw for type arguments which don't point to classes. In these cases, the type would just never typecheck, and it would behave just like the a: Class<Foo?>
b: Class<"foo" | "bar> |
Can you say more about how this would be useful? The only case I can think of is the compatibility shim typealias when a class is moved out into its own module. If this was supported, it would only work for aliases to bare class types, which is of limited utility. An alias may hide that type is not an ordinary class and result in an error (as-is) or a
Again, I think it's more surprising that users could inadvertently build a |
An invariant of a typealias is that: on the type level, it just stands for its aliased type; therefore
I'd expect the failures to be loud, rather than silent! If you try to assign anything to |
|
Updated this to unwrap typealiases during class calculation, so aliases (to aliases)+ to classes now behave as if the underlying class was used directly. Also updated this to error at runtime rather than during |
This PR removes the unconditional type-erasure of
Class<T>toClass.This is a breaking change when
Tis a union type, nullable type, string literal type, parameterized type, type alias, ornothing; these are now error conditions.For convenience, erasure still occurs when
TisunknownorAny. Similarly, the subclass check is skipped whenTis an un-replaced type variable, e.g. in generic classes/methods (type aliases replace the type arg during instantiation).Resolves #1729
Closes apple/pkl-intellij#222