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

Declaring variables with a package type should be disallowed in Rakudo #3600

Closed
p6rt opened this issue Dec 9, 2014 · 10 comments
Closed

Declaring variables with a package type should be disallowed in Rakudo #3600

p6rt opened this issue Dec 9, 2014 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Dec 9, 2014

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

Searchable as RT123397$

@p6rt
Copy link
Author

p6rt commented Dec 9, 2014

From @masak

<masak> m​: role A​::B {}; sub foo(A $a) {}
<camelia> rakudo-moar 662447​: OUTPUT«===SORRY!=== Error while
compiling /tmp/TNiNkxUsdd␤Type A cannot be used as a nominal type on a
parameter [...]
* masak submits LTA rakudobug
<masak> it's true that A, which is in some sense less real than A​::B
(or not "inhabited" or whatever), but the error message should explain
that.
<masak> it's especially confusing that it calls A a "type".
<masak> in fact, I think it would be enough if it just said
"Containing package A cannot be used..."
<moritz> m​: package A { }; sub foo(A $a) { }
<camelia> rakudo-moar 662447​: OUTPUT«===SORRY!=== Error while
compiling /tmp/VqZ7Dwi6I3␤Type A cannot be used as a nominal type on a
parameter [...]
<moritz> masak​: not just containing packages
<masak> good point.
<masak> I mean, in some sense A is a type. in both cases.
<jnthn> It's not even "in some sense".
<masak> but the fact that it's not enough of a useful type is the more
important fact to highlight in the message.
<masak> it's not the kind of type to be used for typing :)
<jnthn> The message is already a LOT better than it just not accepting
anything at runtime.
<masak> granted.
<masak> m​: role A​::B {}; sub foo($a) { say $a }; foo(A)
<camelia> rakudo-moar 662447​: OUTPUT«(A)␤»
<masak> I mean, passing these things ain't a problem.
<jnthn> Just remove the word "Type" at the start of the error and it's
probably a lot less misleading.
<masak> +1
<jnthn> Or at least, less scizophrenic :)

@p6rt
Copy link
Author

p6rt commented Dec 9, 2014

From @masak

<masak> m​: role A​::B {}; sub foo(A $a) {}
<camelia> rakudo-moar 662447​: OUTPUT«===SORRY!=== Error while
compiling /tmp/TNiNkxUsdd␤Type A cannot be used as a nominal type on a
parameter [...]
* masak submits LTA rakudobug
<moritz> m​: package A { }; sub foo(A $a) { }
<camelia> rakudo-moar 662447​: OUTPUT«===SORRY!=== Error while
compiling /tmp/VqZ7Dwi6I3␤Type A cannot be used as a nominal type on a
parameter [...]
<masak> m​: role A​::B {}; my A $a; say $a
<camelia> rakudo-moar 662447​: OUTPUT«(A)␤»
<masak> m​: package A {}; my A $a; say $a
<camelia> rakudo-moar 662447​: OUTPUT«(A)␤»
<masak> why is this fine but the parameter case ain't?
<jnthn> masak​: Because that case is missing some checks, apparently... :P
* masak submits rakudobug
<jnthn> Probably something wants factoring out/re-using...
<masak> should the "package A" one be forbidden too?
<jnthn> Yes, it's the exact same case.
<jnthn> (As in, you can't differentiate the two in terms of the
objects being created)

@p6rt
Copy link
Author

p6rt commented Feb 9, 2015

From @usev6

Nowadays the error message no longer starts with the word 'Type'​:

$ perl6 -e 'role A​::B {}; sub foo(A $a) {}'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a parameter
at -e​:1
------> role A​::B {}; sub foo(A ⏏$a) {}

$ perl6 -e 'package A { }; sub foo(A $a) { }'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a parameter
at -e​:1
------> package A { }; sub foo(A ⏏$a) { }

The same error results with the following code, taken from ticket 117041​:

$ perl6 -e 'role A​::B {method foo(A $a) {} }'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a parameter
at -e​:1
------> role A​::B {method foo(A ⏏$a) {} }

1 similar comment
@p6rt
Copy link
Author

p6rt commented Feb 9, 2015

From @usev6

Nowadays the error message no longer starts with the word 'Type'​:

$ perl6 -e 'role A​::B {}; sub foo(A $a) {}'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a parameter
at -e​:1
------> role A​::B {}; sub foo(A ⏏$a) {}

$ perl6 -e 'package A { }; sub foo(A $a) { }'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a parameter
at -e​:1
------> package A { }; sub foo(A ⏏$a) { }

The same error results with the following code, taken from ticket 117041​:

$ perl6 -e 'role A​::B {method foo(A $a) {} }'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a parameter
at -e​:1
------> role A​::B {method foo(A ⏏$a) {} }

@p6rt
Copy link
Author

p6rt commented Feb 9, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 11, 2015

From @usev6

Behaviour has changed and the latter two commands fail with the same error as the first two (for those compare ticket 123397, https://rt-archive.perl.org/perl6/Ticket/Display.html?id=123397):

$ /perl6 -e 'role A​::B {}; my A $a; say $a'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a variable
at -e​:1
------> role A​::B {}; my A $a⏏; say $a
  expecting any of​:
  constraint

$ perl6 -e 'package A {}; my A $a; say $a'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a variable
at -e​:1
------> package A {}; my A $a⏏; say $a
  expecting any of​:
  constraint

So, this works as expected now. I'm tagging the ticket 'testneeded'.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Feb 11, 2015

From @usev6

Behaviour has changed and the latter two commands fail with the same error as the first two (for those compare ticket 123397, https://rt-archive.perl.org/perl6/Ticket/Display.html?id=123397):

$ /perl6 -e 'role A​::B {}; my A $a; say $a'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a variable
at -e​:1
------> role A​::B {}; my A $a⏏; say $a
  expecting any of​:
  constraint

$ perl6 -e 'package A {}; my A $a; say $a'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a variable
at -e​:1
------> package A {}; my A $a⏏; say $a
  expecting any of​:
  constraint

So, this works as expected now. I'm tagging the ticket 'testneeded'.

@p6rt
Copy link
Author

p6rt commented Feb 11, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 12, 2015

From @jnthn

On Wed Feb 11 11​:30​:22 2015, bartolin@​gmx.de wrote​:

Behaviour has changed and the latter two commands fail with the same
error as the first two (for those compare ticket 123397,
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=123397):

$ /perl6 -e 'role A​::B {}; my A $a; say $a'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a variable
at -e​:1
------> role A​::B {}; my A $a⏏; say $a
expecting any of​:
constraint

$ perl6 -e 'package A {}; my A $a; say $a'
===SORRY!=== Error while compiling -e
A cannot be used as a nominal type on a variable
at -e​:1
------> package A {}; my A $a⏏; say $a
expecting any of​:
constraint

So, this works as expected now. I'm tagging the ticket 'testneeded'.

Added a typed exception for this (and the similar Parameter type error), and tested it.

@p6rt
Copy link
Author

p6rt commented Apr 12, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant