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

clashing type constraints accepted #4568

Closed
p6rt opened this issue Sep 20, 2015 · 5 comments
Closed

clashing type constraints accepted #4568

p6rt opened this issue Sep 20, 2015 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Sep 20, 2015

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

Searchable as RT126123$

@p6rt
Copy link
Author

p6rt commented Sep 20, 2015

From zefram@fysh.org

S02 says this will produce a compiler error​:

$ ./perl6 -e 'my Int $a of Str; say "hi"'
hi

The actual result is that the "of" type is used, and the prefix type
is mostly ignored. (Not entirely ignored​: along the lines of [perl
#​126107], the variable gets its default value from the prefix type,
even if that's inconsistent with the "of" type.) It's also possible to
give two (clashing) "of" types, if the two "of" clauses are separated
by another clause​:

$ ./perl6 -e 'my Int $a of Str is default("z") of Rat; say "hi"'
hi

The last "of" type is used as the type constraint. (But again per [perl
#​126107] the default stays even if it's inconsistent with that type.)

Presumably multiple type constraint clauses, however expressed, should
signal an error. It might be OK to permit multiple type constraints
specifying exactly the same type, but I don't see a real benefit to that.
It seems better to forbid multiple specification whether they clash
or not.

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

From @AlexDaniel

This was fixed in (2015-11-18) rakudo/rakudo@06729d9

$ perl6 -e 'my Int $a of Str; say "hi"'
===SORRY!=== Error while compiling -e
Str not allowed here; variable list already declared with type Int
at -e​:1
------> my Int $a of Str⏏; say "hi"
    expecting any of​:
        constraint

$ perl6 -e 'my Int $a of Str is default("z") of Rat; say "hi"'
===SORRY!=== Error while compiling -e
Str not allowed here; variable list already declared with type Int
Rat not allowed here; variable list already declared with type Str
Default value 'z' will never bind to a parameter of type Rat
at -e​:1

The last one is weirdly explicit, but that's good enough I think. Too much garbage in, some garbage out.

「testneeded」

On 2015-09-20 12​:00​:36, zefram@​fysh.org wrote​:

S02 says this will produce a compiler error​:

$ ./perl6 -e 'my Int $a of Str; say "hi"'
hi

The actual result is that the "of" type is used, and the prefix type
is mostly ignored. (Not entirely ignored​: along the lines of [perl
#​126107], the variable gets its default value from the prefix type,
even if that's inconsistent with the "of" type.) It's also possible to
give two (clashing) "of" types, if the two "of" clauses are separated
by another clause​:

$ ./perl6 -e 'my Int $a of Str is default("z") of Rat; say "hi"'
hi

The last "of" type is used as the type constraint. (But again per [perl
#​126107] the default stays even if it's inconsistent with that type.)

Presumably multiple type constraint clauses, however expressed, should
signal an error. It might be OK to permit multiple type constraints
specifying exactly the same type, but I don't see a real benefit to that.
It seems better to forbid multiple specification whether they clash
or not.

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

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

@p6rt
Copy link
Author

p6rt commented Dec 11, 2017

From @zoffixznet

Tests​: Raku/roast@08ed79bfbb968a8f35153dca

@p6rt
Copy link
Author

p6rt commented Dec 11, 2017

@zoffixznet - 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