Correctly handle duplicate WellKnownType values - #533
Merged
Conversation
The WellKnownType enumeration contains several named items that have the same underlying value. Both First and Last share a value with an actual type entry in the enumeration. A ToString call on those values can return either the type name or First / Last, the runtime does not define which will happen. This comes into play in the static constructor of WellKnownTypes where we assert that the enumeration and s_metadataNames table stay in sync. The code already accounts for First being ambiguous but failed to for Last. This change removes the assumption for Last as well. It also expands out the assert as it was getting to difficult to follow when I added another level of ternary expressions into the mix.
Member
Author
Member
|
I'm not a fan of ifdefs -- any specific reason you chose one instead of a helper method + debug assert call? |
Member
Author
|
@agocke because extending the existing |
Member
|
@jaredpar I would prefer refactoring into a helper method, then calling that in Debug.Assert, if you have no objection. |
Member
Author
|
@agocke I was just going to have a |
Member
|
@jaredpar That works too. Anything that preserves semantic analysis in the compilation regardless of your defined variables :) |
This refactors the code which asserts the enum and name table are in sync into a new method.
Contributor
|
LGTM |
jaredpar
added a commit
that referenced
this pull request
Feb 17, 2015
Correctly handle duplicate WellKnownType values
Member
There was a problem hiding this comment.
If you're going to turn one enum into a particular name, you should assert that they represent the same element, e.g.:
Debug.Assert(WellKnownType.Last == WellKnownType.System_IFormatProvider);
Member
|
👍 |
Member
|
LGTM |
This was referenced Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The WellKnownType enumeration contains several named items that have the
same underlying value. Both First and Last share a value with an actual
type entry in the enumeration. A ToString call on those values can
return either the type name or First / Last, the runtime does not define
which will happen.
This comes into play in the static constructor of WellKnownTypes where
we assert that the enumeration and s_metadataNames table stay in sync.
The code already accounts for First being ambiguous but failed to for
Last.
This change removes the assumption for Last as well. It also expands
out the assert as it was getting to difficult to follow when I added
another level of ternary expressions into the mix.