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

Subtyped attributes can be instantiated with impossible values in Rakudo #999

Closed
p6rt opened this issue May 15, 2009 · 6 comments
Closed

Comments

@p6rt
Copy link

p6rt commented May 15, 2009

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

Searchable as RT65700$

@p6rt
Copy link
Author

p6rt commented May 15, 2009

From @masak

<masak> perl6​: class A { my subset B of Int where { $^n < 10 }; has B
$.c }; A.new( c => 20 ); say "alive"
<p6eval> elf 26845​: OUTPUT«Unknown rule​:
type_declarator​:expect_term␤It needs to be
  added to ast_handlers.␤ at ./elf_h line 2850␤»
<p6eval> ..pugs, rakudo 1f1458​: OUTPUT«alive␤»
* masak submits rakudobug
<masak> rakudo​: class A { my subset B of Int where { $^n < 10 }; has B
$.c }; my $a = A.new( c => 20 ); say $a.c
<p6eval> rakudo 1f1458​: OUTPUT«20␤»
<masak> hah!

I would expect the instantiation to fail, because 20 is not a legit
value of the subtype B.

@p6rt
Copy link
Author

p6rt commented May 20, 2009

From @masak

<jnthn> masak​: In 65700 subset types are now enforced, but here we seem
to hit issues because a lexical subset type doesn't work out too well.
<jnthn> masak​: If you have a moment, feel free to confirm that and
transform the ticket into one about that.
<masak> jnthn​: I can confirm that the evaluation still gives exactly the
same result on my box.
<masak> jnthn​: so if you want, I can change the ticket subject to
"lexical subset types don't work out to well"
<jnthn> masak​: Well, if you do​:
<jnthn> rakudo​: subset B of Int where { $^n &lt; 10 }; class A { has B $.c
}; A.new( c => 20 ); say "alive"
<p6eval> rakudo f62aa0​: OUTPUT«Type mismatch in assignment; expected
something matching type but got something of type Int()␤in Main
(/tmp/I9bgeo9Pp5​:1)␤»
<jnthn> rakudo​: subset B of Int where { $^n &lt; 10 }; class A { has B $.c
}; A.new( c => 2 ); say "alive"
<p6eval> rakudo f62aa0​: OUTPUT«alive␤»
<jnthn> So it's clearly checking the subset type when it's non-lexical.
<jnthn> rakudo​: my subset B of Int where { $^n < 10 }; class A { has B
$.c }; A.new( c => 20 ); say "alive"
<p6eval> rakudo f62aa0​: OUTPUT«alive␤»
<jnthn> It's when we stick a "my" there that we run into issues.
<masak> ah.
* masak updates ticket

@p6rt
Copy link
Author

p6rt commented May 20, 2009

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

@p6rt
Copy link
Author

p6rt commented Oct 26, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S12-subset/subtypes.t

commit 2859f31b0fc228bae3cdbfeac1a9688189582b7d
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Oct 26 21​:48​:36 2009 +0000

  [t/spec] Test for RT 65700, subtyped attributes in instantiation
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;28910 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-subset/subtypes.t b/t/spec/S12-subset/subtypes.t
index 385621d..7eac46d 100644
--- a/t/spec/S12-subset/subtypes.t
+++ b/t/spec/S12-subset/subtypes.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 49;
+plan *;
 
 =begin description
 
@@ -163,4 +163,22 @@ ok 42 ~~ NW1,   'subset declaration without where clause accepts right value';
 ok 4.2 !~~ NW1, 'subset declaration without where clause rejects wrong value';
 ok "x" !~~ NW1, 'subset declaration without where clause rejects wrong value';
 
+# RT #65700
+{
+    subset Small of Int where { $^n < 10 }
+    class RT65700 {
+        has Small $.small;
+    }
+    dies_ok { RT65700.new( small => 20 ) }, 'subset type is enforced as attribute in new() (1)';
+    lives_ok { RT65700.new( small => 2 ) }, 'subset type enforced as attribute in new() (2)';
+
+    my subset Teeny of Int where { $^n < 10 }
+    class T { has Teeny $.teeny }
+    #?rakudo 2 todo 'RT 65700'
+    dies_ok { T.new( small => 20 ) }, 'my subset type is enforced as attribute in new() (1)';
+    lives_ok { T.new( small => 2 ) }, 'my subset type enforced as attribute in new() (2)';
+}
+
+done_testing;
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Sep 20, 2011

From @coke

On Mon Oct 26 14​:50​:37 2009, KyleHa wrote​:

This is an automatically generated mail to inform you that tests are
now available in t/spec/S12-subset/subtypes.t

And we now run this test, with no skips or todos. \o/

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Sep 30, 2011

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

@p6rt p6rt closed this as completed Sep 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant