提交 86062ef9 编写于 作者: P Paul Lietar

Read discriminant as a signed integer if specified by layout.

This ensures it gets sign extended correctly.

Fixes #78
上级 ce8806d1
......@@ -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)?
}
......
enum AB { A = -1, B = 1 }
fn main() {
match AB::A {
AB::A => (),
AB::B => panic!(),
}
match AB::B {
AB::A => panic!(),
AB::B => (),
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册