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

Slurpy positionals cause type constraints to be ignored on named args #6618

Open
p6rt opened this issue Oct 15, 2017 · 3 comments
Open

Slurpy positionals cause type constraints to be ignored on named args #6618

p6rt opened this issue Oct 15, 2017 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 15, 2017

Migrated from rt.perl.org#132307 (status was 'new')

Searchable as RT132307$

@p6rt
Copy link
Author

p6rt commented Oct 15, 2017

From @zoffixznet

The following code tries to pass Str `​:bin` named arg to a Code that wants an `Int` `​:bin` arg.
The typecheck correctly fails, but only if no positional slurpies are present in the signature.

  <Zoffix__> m​: -> Int :$bin {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «Type check failed in binding to parameter '$bin'; expected Int but got Str ("x")␤ in block <unit> at <tmp> line 1␤␤»
  <Zoffix__> m​: -> *@​, Int :$bin {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «[x Str]␤»
  <Zoffix__> m​: -> +@​, Int :$bin {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «[x Str]␤»
  <Zoffix__> m​: -> **@​, Int :$bin {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «[x Str]␤»
  <Zoffix__> m​: -> Int :$bin, *%_ {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «Type check failed in binding to parameter '$bin'; expected Int but got Str ("x")␤ in block <unit> at <tmp> line 1␤␤»
  <Zoffix__> m​: -> Int :$bin, | {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «Type check failed in binding to parameter '$bin'; expected Int but got Str ("x")␤ in block <unit> at <tmp> line 1␤␤»

NOTE​: fixing this will likely have some fallout to watch out for, including test breakage in core (e.g., as I write this, accessing $*ARGFILES would've been
crashing, as its instantiated with an Int for `​:bin` instead of a Bool)

@p6rt
Copy link
Author

p6rt commented Oct 15, 2017

From @zoffixznet

P.S.​: this problem appears to not exist on JVM per https://irclog.perlgeek.de/perl6-dev/2017-10-15#i_15304908

@p6rt
Copy link
Author

p6rt commented Oct 15, 2017

From @zoffixznet

Another couple of datapoints (IRC​: https://irclog.perlgeek.de/perl6-dev/2017-10-15#i_15305041):

The `where` clause gets run even when types don't typecheck and its return value still affects the typecheck​:

  <Zoffix__> m​: -> *@​, Int :$bin where {sleep 2; True} {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «[x Str]␤»
  <Zoffix__> m​: -> *@​, Int :$bin where {sleep 2; False} {say [$bin, $bin.^name]}(​:bin<x>)
  <camelia> rakudo-moar ebb0521bd​: OUTPUT​: «Type check failed in binding to parameter '$bin'; expected Int but got Str ("x")␤ in block <unit> at <tmp> line 1␤␤»

@p6rt p6rt added the moar label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant