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

Splats parameter with free variable bug #5037

Closed
firejox opened this issue Sep 26, 2017 · 5 comments · Fixed by #10172
Closed

Splats parameter with free variable bug #5037

firejox opened this issue Sep 26, 2017 · 5 comments · Fixed by #10172
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler

Comments

@firejox
Copy link
Contributor

firejox commented Sep 26, 2017

https://play.crystal-lang.org/#/r/2spc

def f(x, *y : *T) forall T
  #do something else
end

f(1, 2, 3)

Error message :

Index out of bounds
crystal/src/indexable.cr:0:17 in 'at'
crystal/src/indexable.cr:74:5 in '[]'
crystal/src/compiler/crystal/semantic/cover.cr:130:9 in 'mark_cover'
crystal/src/compiler/crystal/semantic/cover.cr:123:9 in 'mark_cover'
crystal/src/compiler/crystal/semantic/cover.cr:116:13 in 'mark_cover'
crystal/src/compiler/crystal/semantic/cover.cr:86:30 in 'compute_fast_cover'
crystal/src/compiler/crystal/semantic/cover.cr:21:7 in 'all?'
crystal/src/compiler/crystal/semantic/match.cr:134:91 in 'cover_all?'
crystal/src/compiler/crystal/semantic/method_lookup.cr:19:25 in 'lookup_matches'
crystal/src/compiler/crystal/semantic/method_lookup.cr:17:5 in 'lookup_matches'
crystal/src/compiler/crystal/semantic/call.cr:308:17 in 'lookup_matches_with_signature'
crystal/src/compiler/crystal/semantic/call.cr:293:28 in 'lookup_matches_checking_expansion'
crystal/src/compiler/crystal/semantic/call.cr:224:17 in 'lookup_matches_in_type'
crystal/src/compiler/crystal/semantic/call.cr:177:5 in 'lookup_matches_in'
crystal/src/compiler/crystal/semantic/call.cr:175:3 in 'lookup_matches_in'
crystal/src/compiler/crystal/semantic/call.cr:163:7 in 'lookup_matches_without_splat'
crystal/src/compiler/crystal/semantic/call.cr:101:7 in 'lookup_matches'
crystal/src/compiler/crystal/semantic/call.cr:68:5 in 'recalculate'
crystal/src/compiler/crystal/semantic/main_visitor.cr:1279:7 in 'visit'
crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
crystal/src/compiler/crystal/syntax/ast.cr:150:27 in 'accept_children'
crystal/src/compiler/crystal/syntax/visitor.cr:28:11 in 'accept'
crystal/src/compiler/crystal/semantic/main_visitor.cr:7:7 in 'visit_main'
crystal/src/compiler/crystal/semantic/main_visitor.cr:5:5 in 'visit_main:process_finished_hooks:cleanup'
crystal/src/compiler/crystal/semantic.cr:22:7 in 'semantic'
crystal/src/compiler/crystal/compiler.cr:141:7 in 'compile'
crystal/src/compiler/crystal/command.cr:274:7 in 'compile'
crystal/src/compiler/crystal/command.cr:194:14 in 'run_command'
crystal/src/compiler/crystal/command.cr:105:11 in 'run'
crystal/src/compiler/crystal/command.cr:49:5 in 'run'
crystal/src/compiler/crystal/command.cr:48:3 in 'run'
crystal/src/compiler/crystal.cr:8:1 in '__crystal_main'
crystal/src/crystal/main.cr:12:3 in '_crystal_main'
crystal/src/crystal/main.cr:103:5 in 'main_user_code'
crystal/src/crystal/main.cr:91:7 in 'main'
crystal/src/crystal/main.cr:112:3 in 'main'
__libc_start_main
_start
???

crystal -v

Crystal 0.23.0+197 [2eca01b92] (2017-09-26)

LLVM: 3.9.1
Default target: x86_64-unknown-linux-gnu
@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Sep 26, 2017
@makenowjust
Copy link
Contributor

Free variable is not related because this code reproduces the bug:

def foo(x, *y : *{Int32, Int32})
end

foo(1, 2, 3)

@oprypin
Copy link
Member

oprypin commented Sep 27, 2017

I think it's simply that * makes no sense in a type restriction and should not be allowed.

def foo(x : *Int32)
end

foo(1)
Error in line 4: no overload matches 'foo' with type Int32
Overloads are:
 - foo(x : *Int32)

???

@oprypin
Copy link
Member

oprypin commented Sep 27, 2017

Nevermind. It is actually a thing, just not in the context of the original post. It's supposed to be

def f(x, *y : T) forall T
  pp x, y
end

f(1, 2, 3)

@Sija
Copy link
Contributor

Sija commented Sep 27, 2017

@oprypin yep, it works if you omit first argument

def f(*args : *T) forall T
  pp args
end

f(1, 2, 3, :a, 'b', "c")

@makenowjust
Copy link
Contributor

also my example without first argument works:

def foo(*x : *{Int32, Int32})
end

foo(1, 2)

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
Projects
None yet
5 participants