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

Error: undefined constant U #11244

Closed
mamantoha opened this issue Sep 24, 2021 · 5 comments · Fixed by #11246
Closed

Error: undefined constant U #11244

mamantoha opened this issue Sep 24, 2021 · 5 comments · Fixed by #11246
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:collection

Comments

@mamantoha
Copy link
Contributor

Hi team.

I didn't get how to reproduce this error.
But after #10467 my code start fail.

This is the end to the outputt.

In /snap/crystal/874/share/crystal/src/array.cr:208:5

 208 | equals?(other) { |x, y| x == y }
       ^------
Error: instantiating 'equals?((Array(PG::BoolArray) | Array(PG::CharArray) | Array(PG::Float32Array) | Array(PG::Float64Array) | Array(PG::Int16Array) | Array(PG::Int32Array) | Array(PG::Int64Array) | Array(PG::NumericArray) | Array(PG::StringArray) | Array(PG::TimeArray)))'


In /snap/crystal/874/share/crystal/src/indexable.cr:413:33

 413 | def equals?(other : Indexable(U), & : T, U ->) : Bool forall U
                                     ^
Error: undefined constant U

Looks like a typo.

Let me know if I need to provide more info.

/cc @straight-shoota

@mamantoha mamantoha added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Sep 24, 2021
@straight-shoota
Copy link
Member

There is no obvious error with that def. I have no idea how U can be undefined since it's explicitly declared as a free variable.

Stdlib specs are passing.

it "does equals? with custom block" do
a = [1, 3, 2]
b = [3, 9, 4]
c = [5, 7, 3]
d = [1, 3, 2, 4]
f = ->(x : Int32, y : Int32) { (x % 2) == (y % 2) }
a.equals?(b, &f).should be_true
a.equals?(c, &f).should be_false
a.equals?(d, &f).should be_false
end

We need some code to reproduce the error.

@mamantoha
Copy link
Contributor Author

I will try to extract the code to reproduce this issue.

@HertzDevil
Copy link
Contributor

HertzDevil commented Sep 24, 2021

The original error seems to come from here: https://github.com/mamantoha/clear/runs/3681933489

Reduced:

alias Foo = Int32 | Array(Foo)
alias Bar = String | Array(Bar)

x = 1.as(Foo | Bar)
x == x # Error: undefined constant U

For now I suggest not replacing parameter restrictions like Indexable with Indexable(T) forall T until #8973 is settled. (The addition of free variables there is essentially the opposite of #10510, by the way.)

@rubyFeedback
Copy link

The magic constant U has been discovered!

@caspiano
Copy link
Contributor

Looks like this is also showing up for Enumerable#in_groups_of

https://github.com/caspiano/crystal-redis/runs/3864309457?check_suite_focus=true#step:10:12

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:stdlib:collection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants