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

Support type splats inside explicit Unions in type restrictions #10174

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Jan 2, 2021

Implements #8520 (comment). The main use case is when the type being splatted is a generic type var of the enclosing type:

class Foo(*T)
  def self.foo(x : Union(*T))
  end
end

Foo(Int32, String).foo(1) # ok, `Union(*T)` resolves to `Union(Int32, String)`

But it can be any Tuple too:

def foo(x : Union(*{Int32, String})); end
# same as:
def foo(x : Union(Int32, String)); end

This behaviour is consistent with other generic types. Also, unlike other generics multiple splats are allowed inside Union, because they must not be free vars (Union(*T) forall T will never match anything).

@asterite
Copy link
Member

asterite commented Jan 2, 2021

Wow, you are on fire!

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Jan 2, 2021
@HertzDevil HertzDevil changed the title Support type splats inside explicit Unions Support type splats inside explicit Unions in type restrictions Jan 2, 2021
@asterite asterite added this to the 1.0.0 milestone Jan 14, 2021
@asterite asterite merged commit c4b470b into crystal-lang:master Jan 14, 2021
@HertzDevil HertzDevil deleted the feature/explicit-union-type-splat branch January 14, 2021 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants