Is this normal behavior for ToString

Var i As Integer = 1
Var col As String = (i + 2).ToString

Compiler says:

Type mismatch error. Expected String, but got Integer.

Xojo 2026r1.2
macOS Sequoia

Str(i + 2) works fine.

This works as expected:

Var i As Integer = 1
Var col As String = Integer(i + 2).ToString

Sure looks like a bug to me. What if you switch the expression to “2+i"?

This is, unfortunately, expected behavior. Xojo can’t use syntax like that. Casting is necessary, as demonstrated.

Can you give a general description of what’s not permitted?

I’ve tried about four ways to write it up accurately, but I’m not a compiler engineer, so my explanations are not technically accurate and I know it. But essentially code inside parenthesis does not create a function, so there’s no return type, so you can’t apply extension methods to something with no type. That’s why CType(1 + 2, Integer).ToString or Integer(1 + 2).ToString will work - both have a known type of integer.

You might ask “well of course (1 + 2) would produce an integer, why can’t it figure that out?” And that would be a very good question. I believe it should, but it can’t. There are much more complicated examples where the return type is less obvious, but it just doesn’t matter, the compiler can’t handle it.

I believe it’s more that an expression can’t have an attached method.

The same way you can’t say 1.ToString, you can’t say 1+1.ToString, and expect the compiler to figure it out. You cast it into a temporary variable whose type has methods.

Edit: Actually after re-reading your comment we’re saying the same thing! Cheers!