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

Interpreter: Error: BUG: missing upcast_distinct from Tuple(String, String) to String (Crystal::TupleInstanceType to Crystal::NonGenericClassType) #12227

Closed
cyangle opened this issue Jul 9, 2022 · 2 comments · Fixed by #12247
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter

Comments

@cyangle
Copy link
Contributor

cyangle commented Jul 9, 2022

Example code:

class A
  private getter flashes = {} of String => String

  delegate each, to: flashes
end

a = A.new

a.each do |k, v|
  puts k
  puts v
end

Interpreter error:

$ cr i local/bugs/delegate_bug.cr 
Using compiled compiler at /home/chao/git/personal/crystal/.build/crystal
In local/bugs/delegate_bug.cr:9:3

 9 | a.each do |k, v|
       ^---



In local/bugs/delegate_bug.cr:9:3

 9 | a.each do |k, v|
       ^---
Error: compiling a.each do |k, v|

  puts(k)
  puts(v)
end


In local/bugs/delegate_bug.cr:4:3

 4 | delegate each, to: flashes
     ^
Error: expanding macro


There was a problem expanding macro 'delegate'

Called macro defined in /home/chao/git/personal/crystal/src/object.cr:1292:3

 1292 | macro delegate(*methods, to object)

Which expanded to:

 >  1 |     
 >  2 |       
 >  3 |         def each(*args, **options)
 >  4 |           flashes.each(*args, **options)
 >  5 |         end
 >  6 | 
 >  7 |         
 >  8 |           def each(*args, **options)
 >  9 |             flashes.each(*args, **options) do |*yield_args|
 > 10 |               yield *yield_args
 > 11 |             end
 > 12 |           end
 > 13 |         
 > 14 |       
 > 15 |     
 > 16 |   



In local/bugs/delegate_bug.cr:4:3

 4 | delegate each, to: flashes
     ^
Error: expanding macro


There was a problem expanding macro 'delegate'

Called macro defined in /home/chao/git/personal/crystal/src/object.cr:1292:3

 1292 | macro delegate(*methods, to object)

Which expanded to:

 >  1 |     
 >  2 |       
 >  3 |         def each(*args, **options)
 >  4 |           flashes.each(*args, **options)
 >  5 |         end
 >  6 | 
 >  7 |         
 >  8 |           def each(*args, **options)
 >  9 |             flashes.each(*args, **options) do |*yield_args|
 > 10 |               yield *yield_args
 > 11 |             end
 > 12 |           end
 > 13 |         
 > 14 |       
 > 15 |     
 > 16 |   
Error: BUG: missing upcast_distinct from Tuple(String, String) to String (Crystal::TupleInstanceType to Crystal::NonGenericClassType)
@cyangle cyangle added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jul 9, 2022
@asterite
Copy link
Member

asterite commented Jul 10, 2022

Reduced:

def foo
  bar do |*yield_args|
    yield *yield_args
  end
end

def bar
  yield({1, 2})
end

foo do |x, y|
end

It's likely I never got to implement yield with a splat combined with tuple-unpacking.

@asterite
Copy link
Member

Even simpler:

def foo
  yield *{ {1, 2} }
end

foo do |x, y|
end

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

Successfully merging a pull request may close this issue.

3 participants