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
The F#-compiled IL lacks the IsReadOnlyAttribute and the modreq at the property declaration. C# views it as a read-write property. We can't do anything about the latter, but let's try to apply the attribute ourselves (we shouldn't have):
What if the IsReadOnlyAttribute does not exist (like in .NET Standard 2.0 or .NET Framework)? Roslyn generates an internal attribute type and emits that when needed. F#'s compiler tries to find it from anywhere within the assembly's references (even from internal attribute types with the same name), and if it doesn't find it, it doesn't emit it at all. Manually defining an IsReadOnlyAttribute type in the same assembly is ignored.
The bug is reproduced with .NET SDK 5.0.100. inrefs in interface methods are properly compiled like C#.
Consider this simple F# interface:
The equivalent C# interface is this:
The F# snippet's property is compiled to the following IL:
And the C#'s is compiled to this:
The F#-compiled IL lacks the
IsReadOnlyAttributeand themodreqat the property declaration. C# views it as a read-write property. We can't do anything about the latter, but let's try to apply the attribute ourselves (we shouldn't have):And now let's use this interface from C#:
If fails with a mysterious
[CS0570] 'I.Property' is not supported by the languagein the fifth line.Two things stood out:
IsReadOnlyAttributeand themodreqat the interface's property. Both should be automatically added. Looks like the fixes in Emitting IsReadOnlyAttribute on return arguments of type inref<_> #10022 were not covering all cases.IsReadOnlyAttributedoes not exist (like in .NET Standard 2.0 or .NET Framework)? Roslyn generates an internal attribute type and emits that when needed. F#'s compiler tries to find it from anywhere within the assembly's references (even from internal attribute types with the same name), and if it doesn't find it, it doesn't emit it at all. Manually defining anIsReadOnlyAttributetype in the same assembly is ignored.The bug is reproduced with .NET SDK 5.0.100.
inrefs in interface methods are properly compiled like C#.