XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

Interpolated string literals problem with /allowdot+ enabled

Open cpyrgas opened this issue 1 year ago • 1 comments

See below, when allowdot is enabled, i"{d:Year}" results to "Year", instead of "2024"

FUNCTION Start( ) AS VOID
	TestEnabled()	
	TestDisabled()	
RETURN

#pragma options (allowdot, on)
PROCEDURE TestEnabled()
LOCAL IMPLIED d := DateTime.Now

? i"test {d:Year} end" // prints "test Year end", wrong

? i"test {d.Year} end" // "test 2024 end", OK

#pragma options (allowdot, off)
PROCEDURE TestDisabled()
LOCAL IMPLIED d := DateTime.Now

? i"test {d:Year} end" // "test 2024 end", OK

//? i"test {d.Year} end" // error XS0118: 'd' is a variable but is used like a type, OK

cpyrgas avatar Oct 10 '24 11:10 cpyrgas

The problem is that String.Format() , which is used behinde the scene, uses the : operator as delimiter between a value and format info
The compiler now assumes that with /allowdot+ the : operator is indeed the format separator and the . is the send operator. With /allowdot- then the compiler assumes : is the send operator. In both cases :: will be interpreted as separator between value and format.

RobertvanderHulst avatar Oct 13 '24 20:10 RobertvanderHulst