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

Forbid reopening generic types with different type var splats #10167

Merged

Conversation

HertzDevil
Copy link
Contributor

The following (taken from specs) currently compiles:

class Foo(A); end
class Foo(*A); end

class Bar(*A); end
class Bar(A); end

class Baz(*A, B); end
class Baz(A, *B); end

This is misleading because when reopening a generic class/struct the compiler already checks the arity and the names of the formal type vars, but not the splat indices, which affect how many type vars are allowed in instantiations and which formal vars they are bound to. This patch rejects code like the above. (It remains possible to reopen a generic type with omitted type vars.)

Notice how I said "class/struct"; Crystal performs no checks on reopened generic modules, not even their arity. This patch also adds them.

@asterite asterite added this to the 1.0.0 milestone Jan 6, 2021
@asterite asterite merged commit 31d7604 into crystal-lang:master Jan 6, 2021
@HertzDevil HertzDevil deleted the bug/generic-splat-reopening branch January 10, 2021 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants