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

Make Pointer(T)#value= even stricter for generic arguments #10553

Merged

Conversation

HertzDevil
Copy link
Contributor

Follow-up to #10224. Resolves #10544. That code will now produce the following error:

In src/array.cr:409:5

 409 | push(value)
       ^---
Error: instantiating 'push((Hash(Symbol, Int32 | String | Symbol) | Hash(Symbol, Int32 | Symbol)))'


In src/array.cr:1439:12

 1439 | @buffer[@size] = value
               ^
Error: instantiating 'Pointer(Hash(Symbol, Int32 | String | Symbol))#[]=(Int32, (Hash(Symbol, Int32 | String | Symbol) | Hash(Symbol, Int32 | Symbol)))'


In src/pointer.cr:130:29

 130 | (self + offset).value = value
                               ^----
Error: type must be Hash(Symbol, Int32 | String | Symbol), not (Hash(Symbol, Int32 | String | Symbol) | Hash(Symbol, Int32 | Symbol))

The correct check for covariance is implements?, because roughly speaking filter_by only performs intersection between two types. (x.implements?(y) implies x.filter_by(y).implements?(x) && x.implements?(x.filter_by(y)).)

The relation between Nil and Void is not captured by implements? yet, so it is specially handled here. I would expect Void to be a module-like type that has no parents, and whose includer is Nil and nothing else.

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@straight-shoota
Copy link
Member

So it seems the line buffer[0] = buffer[0] / buffer[0] = buffer.value from #10544 (comment) was not necessary to reproduce the error?

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Mar 26, 2021
@HertzDevil
Copy link
Contributor Author

Without that line the snippet would erroneously compile without a codegen error.

@straight-shoota straight-shoota added this to the 1.1.0 milestone Mar 30, 2021
@straight-shoota straight-shoota merged commit e8409c3 into crystal-lang:master Apr 8, 2021
@straight-shoota
Copy link
Member

Thank you, @HertzDevil

@HertzDevil HertzDevil deleted the bug/pointer-value-strict branch April 8, 2021 12:59
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.

Function return type does not match operand type of return inst!
3 participants