Skip to content

Commit

Permalink
Make sure enum type names can't be the same constant names (build wil…
Browse files Browse the repository at this point in the history
…l fail). Resolve an existing conflict that made us realize we had a problem.

Fixes #361
  • Loading branch information
Steve Otteson committed Mar 16, 2021
1 parent 94522b0 commit 8b0b461
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
20 changes: 19 additions & 1 deletion generation/scraper/manualEnums.json
Original file line number Diff line number Diff line change
Expand Up @@ -1596,5 +1596,23 @@
"field": "dwDialMode"
}
]
},
{
"name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_VALUE",
"flags": false,
"members": [
{
"name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_1",
"value": 1
},
{
"name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_2",
"value": 2
},
{
"name": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION",
"value": "PEERDIST_RETRIEVAL_OPTIONS_CONTENTINFO_VERSION_2"
}
]
}
]
]
10 changes: 9 additions & 1 deletion sources/ConstantsScraper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ public static int Run(InvocationContext context)
var renames = ConvertValuePairsToDictionary(renamedNameValuePairs);
var withTypes = ConvertValuePairsToDictionary(withTypeValuePairs);

PartitionUtilsLib.ConstantsScraper.ScrapeConstants(repoRoot, enumJsonFiles, exclusionNamesToPartitions, requiredNamespaces, remaps, withTypes, renames);
try
{
PartitionUtilsLib.ConstantsScraper.ScrapeConstants(repoRoot, enumJsonFiles, exclusionNamesToPartitions, requiredNamespaces, remaps, withTypes, renames);
}
catch (System.Exception e)
{
context.Console.Out.Write($"Failed to scrape constants:\r\n{e.Message}\r\n");
return -1;
}

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions sources/PartitionUtilsLib/ConstantsScraper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ private void WriteEnumsAndRemaps(

if (obj == objectForRemap)
{
if (this.writtenConstants.ContainsKey(obj.name))
{
throw new InvalidOperationException($"Tried to add enum {obj.name} but a constant with the same name already exists.");
}

addedEnum = enumWriter.AddEnum(obj);
}
}
Expand Down

0 comments on commit 8b0b461

Please sign in to comment.