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

Incorrect macro expansion of nilable metaclass restriction #11314

Closed
Blacksmoke16 opened this issue Oct 14, 2021 · 0 comments · Fixed by #11315
Closed

Incorrect macro expansion of nilable metaclass restriction #11314

Blacksmoke16 opened this issue Oct 14, 2021 · 0 comments · Fixed by #11315

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Oct 14, 2021

https://play.crystal-lang.org/#/r/c1eo

I would have expected Bool? to use the Bool?.class overload, however it uses the parent. Commenting out the parent method reveals the cause:

31 | val = StringValue.new("true").get(Bool?)
^--
Error: no overload matches 'StringValue#get' with type (Bool | Nil).class

Overloads are:
- StringValue#get(as : Bool | ::Nil.class)
- StringValue#get(as : Bool.class)

The restriction is being treated as (Bool | Nil.class) instead of (Bool | Nil).class.

@HertzDevil pointed out on Discord this is a result of using record whereby the type restrictions of the expanded methods is incorrect. I.e. from the {{yield}}.

macro f(x)
  {% p x %}
end

f(x : Int32 | String.class)   # => x : Int32 | String.class
f(y : (Int32 | String).class) # => y : Int32 | String.class
Blacksmoke16 added a commit to athena-framework/console that referenced this issue Oct 14, 2021
Switch to explicit struct to work around crystal-lang/crystal/issues/11314
Add some tests for String value type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants