Read discriminant as a signed integer if specified by layout.
This ensures it gets sign extended correctly. Fixes #78
This commit is contained in:
parent
ce8806d141
commit
86062ef930
@ -252,11 +252,16 @@ fn read_discriminant_value(&self, adt_ptr: Pointer, adt_ty: Ty<'tcx>) -> EvalRes
|
||||
let adt_layout = self.type_layout(adt_ty);
|
||||
|
||||
let discr_val = match *adt_layout {
|
||||
General { discr, .. } | CEnum { discr, .. } => {
|
||||
General { discr, .. } | CEnum { discr, signed: false, .. } => {
|
||||
let discr_size = discr.size().bytes();
|
||||
self.memory.read_uint(adt_ptr, discr_size as usize)?
|
||||
}
|
||||
|
||||
CEnum { discr, signed: true, .. } => {
|
||||
let discr_size = discr.size().bytes();
|
||||
self.memory.read_int(adt_ptr, discr_size as usize)? as u64
|
||||
}
|
||||
|
||||
RawNullablePointer { nndiscr, .. } => {
|
||||
self.read_nonnull_discriminant_value(adt_ptr, nndiscr)?
|
||||
}
|
||||
|
13
tests/run-pass/negative_discriminant.rs
Normal file
13
tests/run-pass/negative_discriminant.rs
Normal file
@ -0,0 +1,13 @@
|
||||
enum AB { A = -1, B = 1 }
|
||||
|
||||
fn main() {
|
||||
match AB::A {
|
||||
AB::A => (),
|
||||
AB::B => panic!(),
|
||||
}
|
||||
|
||||
match AB::B {
|
||||
AB::A => panic!(),
|
||||
AB::B => (),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user