Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

raku

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

like image 209
drclaw Avatar asked Mar 13 '19 22:03

drclaw


People also ask

What does no syntax error mean?

Syntax errors are mistakes in the source code, such as spelling and punctuation errors, incorrect labels, and so on, which cause an error message to be generated by the compiler. These appear in a separate error window, with the error type and line number indicated so that it can be corrected in the edit window.

Why am I getting invalid syntax on a colon in Python?

The Python "SyntaxError: invalid syntax" is often caused when we use a single equals sign instead of double equals in an if statement. To solve the error, use double equals == if comparing values and make sure the line of the if statement ends with a colon.

Is misspelling a syntax error?

A syntax error occurs when a programmer writes an incorrect line of code. Most syntax errors involve missing punctuation or a misspelled name. If there is a syntax error in a compiled or interpreted programming language, then the code won't work.

When syntax is wrong then the type of error is?

A semantic error is the violation of syntax rules of a programming language. A3. False, this type of error is the syntax error, not the semantic error.


1 Answers

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.

like image 87
raiph Avatar answered Nov 11 '22 18:11

raiph