mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 14:20:35 +01:00
Type parameters in new Mapping<TypeA, TypeB>/ new Listing<Type> are not checked
#136
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bioball on GitHub (Apr 6, 2024).
This does not throw, but should:
In the below, both types should be checked:
The check should not follow when amended.
This is fine:
This should probably be fine too:
@odenix commented on GitHub (Apr 12, 2024):
A pragmatic solution would be to allow
x: Listing<A> = new Listing {...}but notx = new Listing<A> {...}. This would reflect the (current) reality that generics aren't reified. It would also encourage users to do the right thing and put type annotations on their properties. It might even allow to phase outnew Type {...}in favor of(Type) {...}, which in my view is a nicer literal syntax.@holzensp commented on GitHub (Apr 16, 2024):
That's less simple than you might think. The generic informs the default / IDE type checking. It's a common pattern to define
Listings inline to produce something of a very different type, such asnew Listing<String> { ... }.join(", ")to produce aString.@odenix commented on GitHub (Apr 17, 2024):
Dealing with generics is never simple. Regarding your concrete arguments,
Listing.joinis defined for allListings, not justListing<String>. And IDEs could still try to infer the element type from the given elements. The default sounds like a bigger problem, but maybe there is an acceptable solution.