You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Property initialization doesn't work without space before interpolated string #16696
It is not really related to property initialization, simpler repro:
>letx=$"123";;letx=$"123";;------^^
stdin(2,7): error FS0035: This construct is deprecated:'$' is not permitted as a character in operator names andis reserved for future use
and not so much to interpolated strings either:
>letx=-1;;letx=-1;;------^^
stdin(3,7): error FS0010: Unexpected infix operator in binding. Expected '='or other token.
Well, the last one I think is a different thing, and correctly reported as error.
Actually, if I think about it, also =$ is probably according to F# syntax recognized as an operator, and correctly rejected.
Same thing as let x = 1+-2.
A better error message might be in order.
(In any case, following the formatting guidelines and using Fantomas is helpful ;-))
@Martin521 it is kind of the same thing, because in both cases lexer thinks it sees INFIX_COMPARE_OP, in one case it throws an error there because $ is not allowed there, in the other case, I am actually not sure when the error is thrown (after lexing I think), but it stems from the way this code got lexed IMO.
@abonie Property initialisation is a case where skipping spaces around = makes the most sense. I've met it when writing html dsl, so it looks like <img src="img_girl.jpg"> , note no spaces around equals operator.
This is really bad TBH. another glitch that should be addressed
Easier said than done. It is lexed and parsed like an operator, so it needs be "special cased" for binding, fields and properties assignments (also, how should $"foo"=$"bar" be treated in this case?), but I'm pretty sure by the time we parsed it and produced this diagnostics, there's no "way back" to treating it as assignment.
One possible solution is for us to "deprecate" $ for good, removing it from lexing, so it's never treated as part of the operator, but this will need suggestion/discussion.
We could try to special-case this in the parser: do a check after successfully parsing it as an operator and rewrite the resulting tree if it matches this pattern. We do a similar thing in some other cases already.
We could try to special-case this in the parser: do a check after successfully parsing it as an operator and rewrite the resulting tree if it matches this pattern. We do a similar thing in some other cases already.
It should be relatively safe, since we don't allow defining (=$) operator.
Activity
abonie commentedon Feb 15, 2024
It is not really related to property initialization, simpler repro:
and not so much to interpolated strings either:
Martin521 commentedon Feb 15, 2024
Well, the last one I think is a different thing, and correctly reported as error.
Actually, if I think about it, also
=$is probably according to F# syntax recognized as an operator, and correctly rejected.Same thing as
let x = 1+-2.A better error message might be in order.
(In any case, following the formatting guidelines and using Fantomas is helpful ;-))
abonie commentedon Feb 15, 2024
@Martin521 it is kind of the same thing, because in both cases lexer thinks it sees
INFIX_COMPARE_OP, in one case it throws an error there because$is not allowed there, in the other case, I am actually not sure when the error is thrown (after lexing I think), but it stems from the way this code got lexed IMO.And yeah, not quite sure if this is a bug tbh.
Lanayx commentedon Feb 15, 2024
@abonie Property initialisation is a case where skipping spaces around
=makes the most sense. I've met it when writing html dsl, so it looks like<img src="img_girl.jpg">, note no spaces around equals operator.edgarfgp commentedon May 13, 2024
I think this can be fixed following the same approach than https://github.com/dotnet/fsharp/pull/15923/files
edgarfgp commentedon May 17, 2024
This is really bad TBH. another glitch that should be addressed
vzarytovskii commentedon May 17, 2024
Easier said than done. It is lexed and parsed like an operator, so it needs be "special cased" for binding, fields and properties assignments (also, how should
$"foo"=$"bar"be treated in this case?), but I'm pretty sure by the time we parsed it and produced this diagnostics, there's no "way back" to treating it as assignment.One possible solution is for us to "deprecate"
$for good, removing it from lexing, so it's never treated as part of the operator, but this will need suggestion/discussion.@auduchinok thoughts?
Also, I think message in Rider is outdated:

edgarfgp commentedon May 17, 2024
Never said it was easy 😅. I played around locally with a similar approach than https://github.com/dotnet/fsharp/pull/15923/files and it "works". But now shows that
Namecan't be resolved.auduchinok commentedon Jun 10, 2024
We could try to special-case this in the parser: do a check after successfully parsing it as an operator and rewrite the resulting tree if it matches this pattern. We do a similar thing in some other cases already.
vzarytovskii commentedon Jun 10, 2024
It should be relatively safe, since we don't allow defining
(=$)operator.Allow =$"..." (interpolated string adjacent to =) (dotnet#16696)
Simplify dotnet#16696 tests per review feedback
Allow interpolated string adjacent to '=' (e.g. C(Name=$"value")) (#1…
Handle remaining interpolated-string forms adjacent to '=' (dotnet#16696
Handle remaining interpolated-string forms adjacent to '=' (#16696) (#…
fix(#7199) review round 3: stop entering verbatim mode on operator-su…