Skip to content

Commit

Permalink
Test is default() respects type constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed Dec 12, 2017
1 parent 77a081f commit 7854464
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion S02-names/is_default.t
@@ -1,7 +1,7 @@
use v6;
use Test;

plan 207;
plan 208;

# L<S02/Variables Containing Undefined Values>

Expand Down Expand Up @@ -421,4 +421,28 @@ eval-lives-ok 'my $a is default(Failure.new); 1',
eval-lives-ok 'class NoneFailure { has $!a is default(Failure.new); 1}',
'Failure.new as a default value on an unconstrained Scalar attribute works';

# RT #126107
subtest 'is default() respects type constraint' => {
plan 2;
subtest 'variable' => {
plan 3;
throws-like my $a is default("foo") of Int,
X::Parameter::Default::TypeCheck, 'is default() + of';
throws-like my $a of Int is default("foo"),
X::Parameter::Default::TypeCheck, 'of is default()';
throws-like my Int $a is default("foo"),
X::Parameter::Default::TypeCheck, 'Type $ is default()';
}

subtest 'attribute' => {
plan 3;
throws-like class { has $.a is default("foo") of Int },
X::TypeCheck::Assignment, 'is default() + of';
throws-like class { has $.a of Int is default("foo") },
X::TypeCheck::Assignment, 'of is default()';
throws-like class { has Int $.a is default("foo") },
X::TypeCheck::Assignment, 'Type $ is default()';
}
}

# vim: ft=perl6

0 comments on commit 7854464

Please sign in to comment.