drclaw
drclaw

Reputation: 2483

Mistyped method call with colon syntax. No error. But what does it mean?

I made a typo calling a method with the colon syntax. I missed the space after the colon and the second colon for the named parameter. I've replicated my problem with a simple class:

class Test {
    method myMethod  {
        say "myMethod";
        say %_;
    } 
}

Test.new.myMethod:test<this>; #mistyped call
Test.new.myMethod: :test<this>; #actual call
#Test.new.myMethod:"some_string";

The output is:

myMethod
{}
myMethod
{test => this}
  1. The first myMethod call with no error and no named arguments.
  2. The second works as expected.
  3. The third generates a colon pair compile time error

What does the syntax of the first call mean and why is it not an error? Cheers

Upvotes: 7

Views: 135

Answers (1)

raiph
raiph

Reputation: 32404

Identifiers of the form foo:bar, foo:<baz>, foo:quux<waldo>, foo:quux<waldo>:abc<def> etc. are extended identifiers.

The symbol's longname is aliased to its shortname, the first component of the identifier, so in this case myMethod:test<this> is aliased to myMethod.

Upvotes: 8

Related Questions