Missing equal sign leads to unexpected behavior (whats the use of it ?)

Hi
When i try to instanciate a new Object and have accidentally missed the equal sign
then the Object isn’t instanciated without compiler error (only a warning).
The question for me is what does this statement mean ? Is it treated as a label ?

method Test
var o:Object;
begin
o : new Object; // ← missed equal sign
end;

Trying to instanciate it this way

method Test
begin
var o : new Object; // ← missed equal sign
end;

leads to an error (as expected)

Thanks

1 Like

That sounds like a bug this should emit a compile error, of course. Will log.

1 Like

Logged as bugs://E27245.

hi,
in this case,

o : new Object;

o: // defined as label
new Object; // valid statement

weird, but valid statement

bugs://E27245 was closed as fixed.

Maybe ist’s a good idea to forbid also a local variable afterwards to avoid this ?

Due to possible ambiguity with the colon operator, labels cannot prefix a statement that starts with an identifier (such as for example a method call). They can be followed by any keyword-based statement, including a begin/end, or by a semicolon.

Can you elaborate wioth an example?

Sorry i was not that clear…
The idea is to forbid the same name for a label and a local variable.
So that it’s not possible to declare a local var “o” at the same time/scope as the label “o”

Ah yes. agreed.

Logged as bugs://E27291.

About that, .Net allows having a variable and a label with the same name, continue and do not allow for us then?

What is not allowed is having two labels with the same name, I added the propert error for this.

i’d say not allow it.

Ok, done

1 Like

bugs://E27291 was closed as fixed.