[Issue 18146] New: A case expression of final switch allows to pass wrong enum value
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 30 08:29:56 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=18146
Issue ID: 18146
Summary: A case expression of final switch allows to pass wrong
enum value
Product: D
Version: D2
Hardware: x86_64
URL: http://dlang.org/phobos/
OS: Linux
Status: NEW
Severity: normal
Priority: P3
Component: dmd
Assignee: nobody at puremagic.com
Reporter: kohei-coco at jcom.home.ne.jp
This issue relates enum and final switch.
The situation is shown roughly below.
An enum `Hoge' is defined in file `/foo/bar.d'.
---
enum Hoge: ubyte{Val0, Val1, Val2, Val3, Val4}
---
Then, other file `/foo/baz.d' imports `bar.d'.
template tmp(T){
class Abcd{...}
class Efgh(uint tv0, uint tv1, Hoge typ){
@safe pure nothrow @nogc{
this(){...}
this(in T[] wxyz){
static if( tv0 == tv1 ){
final switch(typ){
case Hoge.Val2:
static assert(typ == Hoge.Val2); // <- this expression throws an
assert exception!
// then, `typ' is equal to Hoge.Val1
break;
case Hoge.Val1:
...;
break;
.
.
.
}
} // End of `static if' statement
} // End of a constructor
}
} // End of class
} // End of template
--
More information about the Digitalmars-d-bugs
mailing list