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

Definitely typed variables have wrong default #5343

Open
p6rt opened this issue May 28, 2016 · 7 comments
Open

Definitely typed variables have wrong default #5343

p6rt opened this issue May 28, 2016 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 28, 2016

Migrated from rt.perl.org#128277 (status was 'open')

Searchable as RT128277$

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @LLFourn

my Str​:D $a = Nil; say $a; # (Str​:D)
say $a.VAR.default; #(Str​:D)

:D variables in general cannot have a default default. Therefore if the
default default should be to throw an exception when it is acessed. My
answer would be​:

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @LLFourn

(continued :P)
Type check failed in assignment to $a; expected Str​:D but got Mu (Mu)
  in block <unit> at -e line 1

It can also happen on assignment to array and hash elements.

On Sat, May 28, 2016 at 9​:59 PM Lloyd Fournier <perl6-bugs-followup@​perl.org>
wrote​:

# New Ticket Created by Lloyd Fournier
# Please include the string​: [perl #​128277]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128277 >

my Str​:D $a = Nil; say $a; # (Str​:D)
say $a.VAR.default; #(Str​:D)

:D variables in general cannot have a default default. Therefore if the
default default should be to throw an exception when it is acessed. My
answer would be​:

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @LLFourn

Should be​:

Type check failed in assignment to $a; expected Str​:D but got (Mu)

(sorry for the spam)

On Sat, May 28, 2016 at 10​:00 PM Lloyd Fournier <lloyd.fourn@​gmail.com>
wrote​:

(continued :P)
Type check failed in assignment to $a; expected Str​:D but got Mu (Mu)
in block <unit> at -e line 1

It can also happen on assignment to array and hash elements.

On Sat, May 28, 2016 at 9​:59 PM Lloyd Fournier <
perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Lloyd Fournier
# Please include the string​: [perl #​128277]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128277 >

my Str​:D $a = Nil; say $a; # (Str​:D)
say $a.VAR.default; #(Str​:D)

:D variables in general cannot have a default default. Therefore if the
default default should be to throw an exception when it is acessed. My
answer would be​:

@p6rt
Copy link
Author

p6rt commented May 28, 2016

From @LLFourn

^^ but that was wrong too.

Type check failed in assignment to $a; expected Str​:D but got Nil

Going to go lie down for a bit now....

On Sat, May 28, 2016 at 10​:02 PM Lloyd Fournier <lloyd.fourn@​gmail.com>
wrote​:

Should be​:

Type check failed in assignment to $a; expected Str​:D but got (Mu)

(sorry for the spam)

On Sat, May 28, 2016 at 10​:00 PM Lloyd Fournier <lloyd.fourn@​gmail.com>
wrote​:

(continued :P)
Type check failed in assignment to $a; expected Str​:D but got Mu (Mu)
in block <unit> at -e line 1

It can also happen on assignment to array and hash elements.

On Sat, May 28, 2016 at 9​:59 PM Lloyd Fournier <
perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Lloyd Fournier
# Please include the string​: [perl #​128277]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=128277 >

my Str​:D $a = Nil; say $a; # (Str​:D)
say $a.VAR.default; #(Str​:D)

:D variables in general cannot have a default default. Therefore if the
default default should be to throw an exception when it is acessed. My
answer would be​:

@p6rt
Copy link
Author

p6rt commented Jun 15, 2016

From @zoffixznet

To add to the discussion, as it seems related. The errors generated in this case are LTA​:

<Zoffix> m​: sub foo ( Str​:D :$a ) {}; foo
<camelia> rakudo-moar ac0dcd​: OUTPUT«Parameter '$a' requires an instance of type Str, but a type object was passed. Did you forget a .new?␤ in sub foo at <tmp> line 1␤ in block <Zoffix> m​: class { method foo (Str​:D :$a) {} }.new.foo
<camelia> rakudo-moar ac0dcd​: OUTPUT«Parameter '$a' requires an instance of type Str, but a type object was passed. Did you forget a .new?␤ in method foo at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

@p6rt
Copy link
Author

p6rt commented Jun 15, 2016

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

@p6rt p6rt added the Bug label Jan 5, 2020
@usev6
Copy link

usev6 commented Oct 7, 2023

The original evaluation fails (with X::TypeCheck::Assignment) now:

$ ./rakudo-m -e 'my Str:D $a = Nil'
Type check failed in assignment to $a; expected Str:D but got Str (Str) (perhaps Nil was assigned to a :D which had no default?)
  in block <unit> at -e line 1

bisectable6 (https://colabti.org/irclogger/irclogger_log/raku-dev?date=2023-10-07#l14) points to rakudo/rakudo@46ef0ea08c and rakudo/rakudo@4eb9a3ef61.

(The related issue #5253 has more context and also has a link to added tests: Raku/roast@fa9a6b0.)

If I'm not missing something the original report in this issue has been addressed.

There are still the two evaluations added as "seemingly related". The output for those has only changed slightly.

$ ./rakudo-m -e 'sub foo (Str:D :$a) {}; foo'
Parameter '$a' of routine 'foo' must be an object instance of type
'Str', not a type object of type 'Str'.  Did you forget a '.new'?
  in sub foo at -e line 1
  in block <unit> at -e line 1

$ ./rakudo-m -e 'class { method foo (Str:D :$a) {} }.new.foo'
Parameter '$a' of routine 'foo' must be an object instance of type
'Str', not a type object of type 'Str'.  Did you forget a '.new'?
  in method foo at -e line 1
  in block <unit> at -e line 1

I'm not sure what to make out of those.

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

2 participants