Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type parameters in new Mapping<TypeA, TypeB>/ new Listing<Type> are not checked #405

Open
bioball opened this issue Apr 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bioball
Copy link
Contributor

bioball commented Apr 5, 2024

This does not throw, but should:

foo = new Listing<Int> {
  "hello"
}

In the below, both types should be checked:

foo: Listing<Int(isEven)> = new Listing<Int(this > 5)> { 1; 2; 3 }

The check should not follow when amended.

This is fine:

foo: new Listing<Int> { 1; 2; 3 }

bar = (foo) { "hello" }

This should probably be fine too:

foo = new Listing<Int> { 1 } { "hello" }
@bioball bioball added the bug Something isn't working label Apr 5, 2024
@translatenix
Copy link
Contributor

translatenix commented Apr 12, 2024

A pragmatic solution would be to allow x: Listing<A> = new Listing {...} but not x = 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 out new Type {...} in favor of (Type) {...}, which in my view is a nicer literal syntax.

@holzensp
Copy link
Contributor

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 as new Listing<String> { ... }.join(", ") to produce a String.

@translatenix
Copy link
Contributor

translatenix commented Apr 17, 2024

Dealing with generics is never simple. Regarding your concrete arguments, Listing.join is defined for all Listings, not just Listing<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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants