Skip to content

Commit

Permalink
fix broken test expectaions due to new behavior in .Net 8.0
Browse files Browse the repository at this point in the history
Up until .Net 7.0, interfaces had 2 attributes: Interface + Abstract
In .Net 8.0 interfaces are emited with a third one: BeforeFieldInit

Can be verified with the following bash script:

cd /tmp
rm -rf test
mkdir test
cd test
echo "public interface IFoo {}"  > itf.cs

echo '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net7.0</TargetFramework></PropertyGroup></Project>'  >  itf.csproj
docker run -it -v /tmp/test/:/code mcr.microsoft.com/dotnet/sdk:7.0 bash -c "cd /code;
dotnet build;
dotnet tool install -g ilspycmd;
DOTNET_ROLL_FORWARD=LatestMajor /root/.dotnet/tools/ilspycmd -il /code/bin/Debug/net7.0/itf.dll > 7.il
"

echo '<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>net8.0</TargetFramework></PropertyGroup></Project>'  >  itf.csproj
docker run -it -v /tmp/test/:/code mcr.microsoft.com/dotnet/sdk:8.0 bash -c "cd /code;
dotnet build;
dotnet tool install -g ilspycmd;
DOTNET_ROLL_FORWARD=LatestMajor /root/.dotnet/tools/ilspycmd -il /code/bin/Debug/net8.0/itf.dll > 8.il
"
  • Loading branch information
adrianoc committed Jan 28, 2024
1 parent b7ac6f4 commit dd9b475
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Cecilifier.Core/Misc/CecilDefinitionsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public static string DefaultTypeAttributeFor(TypeKind typeKind, bool hasStaticCt
{
TypeKind.Struct => "TypeAttributes.Sealed |" + basicClassAttrs,
TypeKind.Class => basicClassAttrs,
TypeKind.Interface => "TypeAttributes.Interface | TypeAttributes.Abstract",
TypeKind.Interface => "TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit",
TypeKind.Delegate => "TypeAttributes.Sealed",
TypeKind.Enum => string.Empty,
_ => throw new Exception("Not supported type declaration: " + typeKind)
Expand Down

0 comments on commit dd9b475

Please sign in to comment.