Issue 4517 - final switch over with base type allows missing values #662

Merged
merged 1 commit into from Jul 17, 2012

Conversation

Projects
None yet
3 participants
Member

yebblies commented Jan 31, 2012

Integral promotions kills the type of the condition and the case expressions, so keep track of the original enum type and allow cases to match if they evaluate to the same integer expression.

http://d.puremagic.com/issues/show_bug.cgi?id=4517

@MartinNowak MartinNowak commented on the diff Feb 1, 2012

src/statement.c
@@ -3007,7 +3011,7 @@ void StaticAssertStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
for (size_t j = 0; j < cases->dim; j++)
{ CaseStatement *cs = (*cases)[j];
- if (cs->exp->equals(em->value))
+ if (cs->exp->equals(em->value) || cs->exp->toInteger() == em->value->toInteger())
@MartinNowak

MartinNowak Feb 1, 2012

Member

Will this work with enum E : float { A, B, }?

@yebblies

yebblies Feb 1, 2012

Member

I suppose not. Thanks.

@yebblies

yebblies Feb 1, 2012

Member

Never mind, floats are not supported in switches anyway.

@MartinNowak

MartinNowak Feb 1, 2012

Member

Ah right, forgot about that.

@yebblies yebblies Issue 4517 - final switch over with base type allows missing values
Integral promotions kills the type of the condition and the case expressions, so keep track of the original enum type and allow cases to match if they evaluate to the same integer expression.

Fixes issue4517
ef6d2e1

@donc donc pushed a commit that referenced this pull request Jul 17, 2012

@don-clugston-sociomantic don-clugston-sociomantic Merge pull request #662 from yebblies/issue4517
Issue 4517 - final switch over with base type allows missing values
00778d3

@donc donc merged commit 00778d3 into dlang:master Jul 17, 2012

yebblies deleted the yebblies:issue4517 branch Nov 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment