Skip to content

Commit

Permalink
Fix bug where enums with underlying types would cause a crash (#351)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
  • Loading branch information
Genbox and Vannevelj authored Sep 13, 2024
1 parent 838ac79 commit da08e53
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
Expand All @@ -27,15 +27,15 @@ jobs:
DeployExtension: False

- name: Collect artifacts - VSIX
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: sharpsource.vsix
path: SharpSource\SharpSource.Vsix\bin\Release\net472\SharpSource.vsix
if-no-files-found: error
retention-days: 5

- name: Collect artifacts - nugets
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: sharpsource.nupkg
path: '**/SharpSource*.nupkg'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/changelog-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Restore NuGet Packages
run: dotnet restore sharpsource.sln
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: windows-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Get version from CHANGELOG.md
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
Expand All @@ -31,35 +31,35 @@ jobs:
env:
DeployExtension: False
- name: Collect artifacts - Changelog
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: CHANGELOG.md
path: ./CHANGELOG.md
retention-days: 30
if-no-files-found: error
- name: Collect artifacts - README
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: README.md
path: ./README.md
retention-days: 30
if-no-files-found: error
- name: Collect artifacts - VSIX
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: sharpsource.vsix
path: SharpSource\SharpSource.Vsix\bin\Release\net472\SharpSource.vsix
if-no-files-found: error
retention-days: 30
- name: Collect artifacts - publishmanifest
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: publishManifest.json
path: SharpSource\SharpSource.Vsix\publishManifest.json
if-no-files-found: error
retention-days: 30
- name: Collect artifacts - nugets
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: sharpsource.nupkg
path: '**/SharpSource*.nupkg'
Expand All @@ -71,15 +71,15 @@ jobs:
needs: pack
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: sharpsource.nupkg
path: .
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: sharpsource.vsix
path: .
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: CHANGELOG.md
path: .
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download a single artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: sharpsource.nupkg
- name: Push to NuGet
Expand All @@ -130,7 +130,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Download a single artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: sharpsource.nupkg
- name: Push to Github
Expand All @@ -146,15 +146,15 @@ jobs:
needs: pack
runs-on: windows-latest
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: sharpsource.vsix
path: .
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: publishManifest.json
path: .
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: README.md
path: .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Restore NuGet Packages
run: dotnet restore sharpsource.sln
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version-bump-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: dorny/paths-filter@v2
id: changes
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# CHANGELOG
https://keepachangelog.com/en/1.0.0/

## [1.24.1] - 2024-09-10
- `EnumWithoutDefaultValue`: No longer crashes when using an enum that is not `int`, courtesy of @Genbox

## [1.24.0] - 2024-02-20
- All analysers will no longer report diagnostics in generated code

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ or add a reference yourself:

```xml
<ItemGroup>
<PackageReference Include="SharpSource" Version="1.24.0" PrivateAssets="All" />
<PackageReference Include="SharpSource" Version="1.24.1" PrivateAssets="All" />
</ItemGroup>
```

Expand Down
2 changes: 1 addition & 1 deletion SharpSource/SharpSource.Package/SharpSource.Package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<PropertyGroup>
<PackageId>SharpSource</PackageId>
<PackageVersion>1.24.0</PackageVersion>
<PackageVersion>1.24.1</PackageVersion>
<Authors>Jeroen Vannevel</Authors>
<PackageLicenseUrl>https://github.com/Vannevelj/SharpSource/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/Vannevelj/SharpSource</PackageProjectUrl>
Expand Down
40 changes: 40 additions & 0 deletions SharpSource/SharpSource.Test/EnumWithoutDefaultValueTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -85,4 +86,43 @@ enum Test {{

await VerifyCS.VerifyNoDiagnostic(original);
}

[TestMethod]
[DataRow("None")]
[DataRow("Unknown")]
public async Task EnumWithoutDefaultValue_RightName_NegativeValue(string memberName)
{
var original = $@"
enum [|Test|] : short {{
{memberName} = -1
}}";

await VerifyCS.VerifyNoDiagnostic(original);
}

[TestMethod]
[DynamicData(nameof(GetEnumTypes), DynamicDataSourceType.Method)]
public async Task EnumWithoutDefaultValue_RightName_WithDifferentType(string memberName, string dataType)
{
var original = $@"
enum Test : {dataType} {{
{memberName} = 0
}}";

await VerifyCS.VerifyNoDiagnostic(original);
}

public static IEnumerable<object[]> GetEnumTypes()
{
var memberNames = new[] { "None", "Unknown" };
var dataTypes = new[] { "byte", "sbyte", "short", "ushort", "int", "uint", "long", "ulong" };

foreach (var memberName in memberNames)
{
foreach (var dataType in dataTypes)
{
yield return new object[] { memberName, dataType };
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext context)
return;
}

if (!membersOfInterest.Any(m => m is IFieldSymbol { ConstantValue: 0 }))
if (!membersOfInterest.Any(m => m is IFieldSymbol f && Convert.ToDouble(f.ConstantValue) == 0))
{
Report(symbol, context);
}
Expand Down

0 comments on commit da08e53

Please # to comment.