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

Rakudo should do type checking on the invocant parameter on methods #1451

Closed
p6rt opened this issue Dec 20, 2009 · 6 comments
Closed

Rakudo should do type checking on the invocant parameter on methods #1451

p6rt opened this issue Dec 20, 2009 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 20, 2009

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

Searchable as RT71476$

@p6rt
Copy link
Author

p6rt commented Dec 20, 2009

From @masak

<masak> mwhaha!
<masak> I'm back to bother you with my endless bug reports :)
<masak> rakudo​: class A { method foo(@​a​: $x) { say $x } }; A.new.foo("OH HAI")
<p6eval> rakudo 8dc189​: ( no output )
<masak> locally, "OH HAI"
* masak submits rakudobug

I'm not really sure what should happen. Perhaps a compile-time error
saying that the user is not to type the invocant parameter, or else.

@p6rt
Copy link
Author

p6rt commented Apr 16, 2010

From @masak

<masak> rakudo​: class A {}; class B { method foo(A $foo​:) { say $foo.WHAT } }; B.new.foo
<p6eval> rakudo 78faa0​: OUTPUT«B()␤»
<masak> jnthn​: can I submit this as a rakudobug?
<jnthn> masak​: Probably is one...
<jnthn> masak​: Think we've seen it before...the nominal type isn't enforced for the invocant.
<jnthn> But don't recall seeing a ticket to go with it.
<masak> I can look for it in RT before I submit.
<masak> this one is similar enough, I think​: http://rt.perl.org/rt3/Ticket/Display.html?
id=71476
<jnthn> Well
<jnthn> You are allowed to type the invocant parameter
<masak> sure!
<jnthn> It's just that Rakudo doesn't actually enforce it
<jnthn> I forget why.
<jnthn> The ticket seems to suggest you can't though.
<masak> oh
* masak looks again
<jnthn> "Perhaps a compile-time error saying that the user is not to type the invocant
parameter, or else."
<masak> jnthn​: I'll just add this conversation as a comment to that bug.
<masak> and maybe change its subject.
<moritz_> "this ticket now says the opposite of what it said before"

S12 says "You need not declare the invocant's type, since the lexical class of the invocant is
known in any event because methods must be declared in the class of the invocant, though
of course the actual (virtual) type may be a derived type of the lexical type. You could declare
a more restrictive type, but that would probably be a bad thing for proper polymorphism. You
may explicitly type the invocant with the lexical type, but any check for that will be optimized
away."

@p6rt
Copy link
Author

p6rt commented Apr 16, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 4, 2010

From @jnthn

On Sun Dec 20 13​:49​:07 2009, masak wrote​:

<masak> mwhaha!
<masak> I'm back to bother you with my endless bug reports :)
<masak> rakudo​: class A { method foo(@​a​: $x) { say $x } };
A.new.foo("OH HAI")
<p6eval> rakudo 8dc189​: ( no output )
<masak> locally, "OH HAI"
* masak submits rakudobug

I'm not really sure what should happen. Perhaps a compile-time error
saying that the user is not to type the invocant parameter, or else.

It now bothers to type check the invocant and complains, rather than
just letting it pass.

Given to moritz++ for tests.

Jonathan

@p6rt p6rt closed this as completed Jul 5, 2010
@p6rt
Copy link
Author

p6rt commented Jul 5, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 6, 2010

From @kyleha

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

commit 1b0acff2dd40389c3093751fec9d596734188835
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Jul 5 06​:55​:18 2010 +0000

  [t/spec] test for RT #​71476, invocant type constraint should be checked at method call time
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31551 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-methods/instance.t b/t/spec/S12-methods/instance.t
index d3824a5..9c4cef1 100644
--- a/t/spec/S12-methods/instance.t
+++ b/t/spec/S12-methods/instance.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 33;
+plan 34;
 
 =begin pod
 
@@ -199,4 +199,13 @@ is AnonInvocant.new().me, AnonInvocant, 'a typed $: as invocant is OK';
     is Y.new.y(*), 1, 'Can dispatch y(*)';
 }
 
+{
+    class InvocantTypeCheck {
+        method x(Int $a:) {
+            42;
+        }
+    }
+    dies_ok { InvocantTypeCheck.new.x() }, 'Invocant type is checked';
+}
+
 # vim: ft=perl6

@p6rt p6rt added the Bug label Jan 5, 2020
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

1 participant