Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The compiler automatically generates an IsReadOnlyAttribute on downlevel frameworks even if we have already defined it. #15313

Closed
teo-tsirpanis opened this issue Jun 5, 2023 · 2 comments · Fixed by #15316
Assignees
Labels
Area-Compiler-CodeGen IlxGen, ilwrite and things at the backend Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@teo-tsirpanis
Copy link
Contributor

Please provide a succinct description of the issue.

Repro steps

Source:

#if NETSTANDARD2_0
namespace System.Runtime.CompilerServices

type IsReadOnlyAttribute() =
    inherit System.Attribute()
#endif

namespace fsharp_ns2_repro

[<Struct;System.Runtime.CompilerServices.IsReadOnly>]
type MyRecord = {X : int}

Project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net7.0;netstandard2.0</TargetFrameworks>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Library.fs" />
  </ItemGroup>
</Project>

Expected behavior

Project compiles successfully on both frameworks.

Actual behavior

Project compiles successfully on .NET 7, fails to compile on .NET Standard 2.0 with:

FSC : error FS2014: A problem occurred writing the binary 'C:\Users\teo\code\fsharp-ns2-repro\obj\Debug\netstandard2.0\fsharp-ns2-repro.dll': duplicate entry 'System.Runtime.CompilerServices.IsReadOnlyAttribute' in type index table [C:\Users\teo
\code\fsharp-ns2-repro\fsharp-ns2-repro.fsproj::TargetFramework=netstandard2.0]

Known workarounds

Don't bother with IsReadOnlyAttribute and let the compiler apply it when it sees fit. I guessed that it would apply it to MyRecord, but it applies it only on X's getter. It's the same thing in this case, but I tried defining a method to the record, and was not marked as readonly.

Related information

Encountered when updating the .NET SDK from 7.0.2xx to 7.0.3xx (teo-tsirpanis/Farkle#104). Likely introduced in #14941.

@github-actions github-actions bot added this to the Backlog milestone Jun 5, 2023
@0101 0101 added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Compiler-CodeGen IlxGen, ilwrite and things at the backend and removed Needs-Triage labels Jun 5, 2023
@KevinRansom KevinRansom moved this from Not Planned to Planned in F# Compiler and Tooling Jun 5, 2023
@KevinRansom KevinRansom modified the milestones: Backlog, June-2023 Jun 5, 2023
KevinRansom added a commit to KevinRansom/fsharp that referenced this issue Jun 5, 2023
abonie pushed a commit that referenced this issue Jun 6, 2023
…ute on downlevel frameworks even if we have already defined it. (#15316)

* Fix #15313

* fantomas
@github-project-automation github-project-automation bot moved this from Planned to Done in F# Compiler and Tooling Jun 6, 2023
T-Gro pushed a commit that referenced this issue Jun 6, 2023
* Fix #15313 - The compiler automatically generates an IsReadOnlyAttribute on downlevel frameworks even if we have already defined it. (#15316)


---------

Co-authored-by: Kevin Ransom (msft) <codecutter@hotmail.com>
Co-authored-by: Vlad Zarytovskii <vzaritovsky@hotmail.com>
@teo-tsirpanis
Copy link
Contributor Author

That was fast, thanks! Will it be backported to 17.6?

@vzarytovskii
Copy link
Member

vzarytovskii commented Jun 7, 2023

That was fast, thanks! Will it be backported to 17.6?

We'll see what can be done, but likely it's not going to hit the bar.

Though still going to go to 7.0 (current target for 17.7 branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-CodeGen IlxGen, ilwrite and things at the backend Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
4 participants