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

:D smiley is not respected when assigning to Nil #5253

Closed
p6rt opened this issue Apr 22, 2016 · 9 comments
Closed

:D smiley is not respected when assigning to Nil #5253

p6rt opened this issue Apr 22, 2016 · 9 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 22, 2016

Migrated from rt.perl.org#127958 (status was 'resolved')

Searchable as RT127958$

@p6rt
Copy link
Author

p6rt commented Apr 22, 2016

From @LLFourn

m​: say my Any​:D $a = Nil # (Any​:D)

that should be an error.

http://irclog.perlgeek.de/perl6/2016-04-22#i_12377287

@p6rt
Copy link
Author

p6rt commented Jul 10, 2016

From @zoffixznet

Still present in 405519

<Zoffix> m​: say my Any​:D $a = Any
<camelia> rakudo-moar 405519​: OUTPUT«Type check failed in assignment to $a; expected Any​:D but got Any (Any)␤ in block <unit> at <tmp> line 1␤␤»
<Zoffix> m​: say my Any​:D $a = Nil
<camelia> rakudo-moar 405519​: OUTPUT«(Any​:D)␤»

@p6rt
Copy link
Author

p6rt commented Jul 22, 2016

From @skids

rakudo PR #​829 should fix this on moarvm. JVM and JS fixes may also be needed.

@p6rt
Copy link
Author

p6rt commented Jul 22, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 24, 2016

From @gfldex

16​:02 < TimToady> I think my Int​:D $a = 42 should initialize as soon as possible, and never allow assignment of anything that ~~ Nil
16​:02 < TimToady> bare "my Int​:d $a;" should be illegal at compile time
16​:02 < TimToady> the invariant is what's wanted, and that's what we should maintain
16​:04 < TimToady> this is one of those spots where we should torment the implementor on behalf of the user, I suspect

16​:10 < TimToady> so when the symbol is introduced, we can temporarily poke an Int​:D into it, but as soon as the "my" executes and sets the value the first time, it should never be reset to Int​:D except by re-entry
16​:11 < TimToady> if we know the value at compile time, we can even just initialize it to 42 when the symbol is created, even before the 'my' executes

@p6rt
Copy link
Author

p6rt commented Jul 24, 2016

From @skids

On Fri Jul 22 15​:34​:49 2016, bri@​abrij.org wrote​:

rakudo PR #​829 should fix this on moarvm. JVM and JS fixes may also
be needed.

I added some error awesomeization to that PR so that now​:

$ perl6 -e 'my Int​:D @​a; @​a[0] = Nil; @​a.say;'
Type check failed in assignment to @​a; expected type Int​:D cannot be itself (perhaps Nil was assigned to a :D which had no default?)
  in block <unit> at -e line 1

$ perl6 -e 'my Int​:D @​a; @​a[0] = Int​:D; @​a.say;'
Type check failed in assignment to @​a; expected type Int​:D cannot be itself (perhaps Nil was assigned to a :D which had no default?)
  in block <unit> at -e line 1

$ perl6 -e 'my Int​:D $a = 42; $a := Nil; $a.say;'
Type check failed in binding; expected Int​:D but got Nil (Nil)
  in block <unit> at -e line 1

$ perl6 -e 'my Int​:D $a = 42; $a := Int​:D; $a.say;'
Type check failed in binding; expected type Int​:D cannot be itself
  in block <unit> at -e line 1

And though there is an awesomeization for sub return types it does not work,
because the X is being fed the raw type not the smilied typed.

$ perl6 -e '{ sub f() of Str​:D { Str​:D }; f(); CATCH { $_.expected.WHAT.say }}'
(Str)
Type check failed for return value; expected Str but got Str​:D (Str​:D)
  in sub f at -e line 1
  in block <unit> at -e line 1

...that is a separate issue so, not touching it.

Another thing I'm not touching is this​:

$ perl6 -e 'my Int​:D %a; %a<a> := Str; %a.say;'
{a => (Str)}

...note how the array version fails (correctly) in the binder​:

$ perl6 -e 'my Int​:D @​a; @​a[0] := Str; @​a.say;'
Cannot resolve caller BIND-POS(Array[Int​:D]​: Int, Str); none of these signatures match​:
  (Array​:D $​: Int $pos, Int​:D \bindval, *%_)
  (Array​:D $​: int $pos, Int​:D \bindval, *%_)
  in block <unit> at -e line 1
$ perl6 -e 'my Int​:D @​a; @​a.^find_method("BIND-POS").candidates».signature.say'
((Array​:D $​: Int $pos, Int​:D \bindval, *%_) (Array​:D $​: int $pos, Int​:D \bindval, *%_))
$ perl6 -e 'my Int​:D %a; %a.^find_method("BIND-KEY").candidates».signature.say'
((Hash​:D $​: \key, Mu \bindval, *%_))

...and note in Hash.pm there are comments on the hash class BIND-KEY method saying
it should be a multi, but that blows up setting compilation -- I verified this is still
currently the case. That might be related.

One thing the awesomeized errors do not get right is this, but it is in a half broken,
half NYI state anyway​:

$ perl6 -e 'role A[​::T $t] { has T​:D $.f = 1; }; A[Int].new'
X​::TypeCheck​::Assignment exception produced no message
  in any at gen/moar/m-Metamodel.nqp line 1736
  in block <unit> at -e line 1

(versus current behavior, also wrong as it should not fail, if ever implemented)​:

(03​:31​:08 PM) skids​: m​: role A[​::T $t] { has T​:D $.f = 1; }; A[Int].new
(03​:31​:09 PM) camelia​: rakudo-moar 478671​: OUTPUT«Type check failed in assignment to $!f; expected T​:D but got Int (1)␤ in any at gen/moar/m-Metamodel.nqp line 1736␤ in block <unit> at <tmp> line 1␤␤»

Evidence that it should not be hoped to work​:

$ perl6 -e 'role A[​::T $t] { method f { (T​:D).perl.say } }; A[Int].new.f()'
===SORRY!=== Error while compiling -e
Type too complex to form a definite type
at -e​:1

@p6rt
Copy link
Author

p6rt commented Jul 25, 2016

From @zoffixznet

Fixed in rakudo/rakudo@5500404

Tests added in Raku/roast@fa9a6b0

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Jul 25, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Jul 25, 2016
@p6rt
Copy link
Author

p6rt commented Jul 28, 2016

From @LLFourn

Tests​:
Raku/roast@fa9a6b0

On Mon, Jul 25, 2016 at 8​:19 AM Brian S. Julin via RT <
perl6-bugs-followup@​perl.org> wrote​:

On Fri Jul 22 15​:34​:49 2016, bri@​abrij.org wrote​:

rakudo PR #​829 should fix this on moarvm. JVM and JS fixes may also
be needed.

I added some error awesomeization to that PR so that now​:

$ perl6 -e 'my Int​:D @​a; @​a[0] = Nil; @​a.say;'
Type check failed in assignment to @​a; expected type Int​:D cannot be
itself (perhaps Nil was assigned to a :D which had no default?)
in block <unit> at -e line 1

$ perl6 -e 'my Int​:D @​a; @​a[0] = Int​:D; @​a.say;'
Type check failed in assignment to @​a; expected type Int​:D cannot be
itself (perhaps Nil was assigned to a :D which had no default?)
in block <unit> at -e line 1

$ perl6 -e 'my Int​:D $a = 42; $a := Nil; $a.say;'
Type check failed in binding; expected Int​:D but got Nil (Nil)
in block <unit> at -e line 1

$ perl6 -e 'my Int​:D $a = 42; $a := Int​:D; $a.say;'
Type check failed in binding; expected type Int​:D cannot be itself
in block <unit> at -e line 1

And though there is an awesomeization for sub return types it does not
work,
because the X is being fed the raw type not the smilied typed.

$ perl6 -e '{ sub f() of Str​:D { Str​:D }; f(); CATCH {
$_.expected.WHAT.say }}'
(Str)
Type check failed for return value; expected Str but got Str​:D (Str​:D)
in sub f at -e line 1
in block <unit> at -e line 1

...that is a separate issue so, not touching it.

Another thing I'm not touching is this​:

$ perl6 -e 'my Int​:D %a; %a<a> := Str; %a.say;'
{a => (Str)}

...note how the array version fails (correctly) in the binder​:

$ perl6 -e 'my Int​:D @​a; @​a[0] := Str; @​a.say;'
Cannot resolve caller BIND-POS(Array[Int​:D]​: Int, Str); none of these
signatures match​:
(Array​:D $​: Int $pos, Int​:D \bindval, *%_)
(Array​:D $​: int $pos, Int​:D \bindval, *%_)
in block <unit> at -e line 1
$ perl6 -e 'my Int​:D @​a;
@​a.^find_method("BIND-POS").candidates».signature.say'
((Array​:D $​: Int $pos, Int​:D \bindval, *%_) (Array​:D $​: int $pos, Int​:D
\bindval, *%_))
$ perl6 -e 'my Int​:D %a;
%a.^find_method("BIND-KEY").candidates».signature.say'
((Hash​:D $​: \key, Mu \bindval, *%_))

...and note in Hash.pm there are comments on the hash class BIND-KEY
method saying
it should be a multi, but that blows up setting compilation -- I verified
this is still
currently the case. That might be related.

One thing the awesomeized errors do not get right is this, but it is in a
half broken,
half NYI state anyway​:

$ perl6 -e 'role A[​::T $t] { has T​:D $.f = 1; }; A[Int].new'
X​::TypeCheck​::Assignment exception produced no message
in any at gen/moar/m-Metamodel.nqp line 1736
in block <unit> at -e line 1

(versus current behavior, also wrong as it should not fail, if ever
implemented)​:

(03​:31​:08 PM) skids​: m​: role A[​::T $t] { has T​:D $.f = 1; }; A[Int].new
(03​:31​:09 PM) camelia​: rakudo-moar 478671​: OUTPUT«Type check failed in
assignment to $!f; expected T​:D but got Int (1)␤ in any at
gen/moar/m-Metamodel.nqp line 1736␤ in block <unit> at <tmp> line 1␤␤»

Evidence that it should not be hoped to work​:

$ perl6 -e 'role A[​::T $t] { method f { (T​:D).perl.say } }; A[Int].new.f()'
===SORRY!=== Error while compiling -e
Type too complex to form a definite type
at -e​:1

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