This project is read-only.

Bug: CodeDom doesn't escape F# keyword


From FSBugs
When I’m using xsd.exe with the F# codedom – if I have attributes called ‘type’ or ‘function’ or some other F# reserved word in my xml schema, they’re not cleaned up by the CodeDom and get thrown out into the code where the compiler complains about it. Some people here think that’s a bug – I’m not sure what the C# codedom does. Personally I think it’s a case for more defensive coding, but xsd should probably clean it up – it is valid XML, after all.


MrTines wrote Apr 25, 2011 at 9:02 AM

It doesn't look like this is amenable to a point fix -- the (++) and (--) functions are too general; we don't want to wrap real class or module declarations like
    -- " = " -- structOrCls
when structOrCls has value "class", say.

It would probably come down to wrapping every use of a <code dom type>.Name in an escaping wrapper like
let makeEnquotededIdentifier str = 
  if (fsKeyWords.Contains(str)) then "``"+str+"``" else str;

MrTines wrote Jun 17, 2011 at 8:40 PM

The C# CodeDOM uses the @-prefix to escape keywords (e.g. @return for a variable called return), so the backtick escaping would be equivalent.

The -! operator adds a prefixing underscore via makeValidIdentifier, so judicious replacement of -- x.Name with -! x.Name would do; it would just be nicer to do the language defined keyword escaping through some similar operator.

The public CreateEscapedIdentifier method should also strictly backtick-escape, to have the analogous behaviour to the C# @-prefixing behaviour; the unused function Generator.makeEscapedIdentifier would then be the same as the proposed makeEnquotededIdentifier above.

wrote Feb 22, 2013 at 12:25 AM