core: Allow implicit promotions of integral literals

It should not matter, since it is the value of the literal that matters
with respect to the const generic variable.
This commit is contained in:
David Mak 2023-12-20 18:30:44 +08:00
parent bd792904f9
commit e435b25756
1 changed files with 17 additions and 1 deletions

View File

@ -789,9 +789,25 @@ impl Unifier {
(TLiteral { values: val1, .. }, TLiteral { values: val2, .. }) => { (TLiteral { values: val1, .. }, TLiteral { values: val2, .. }) => {
for (v1, v2) in zip(val1, val2) { for (v1, v2) in zip(val1, val2) {
if v1 != v2 { if v1 != v2 {
let symbol_value_to_int = |value: &SymbolValue| -> Option<i128> {
match value {
SymbolValue::I32(v) => Some(*v as i128),
SymbolValue::I64(v) => Some(*v as i128),
SymbolValue::U32(v) => Some(*v as i128),
SymbolValue::U64(v) => Some(*v as i128),
_ => None,
}
};
// Try performing integer promotion on literals
let v1i = symbol_value_to_int(v1);
let v2i = symbol_value_to_int(v2);
if v1i != v2i {
return self.incompatible_types(a, b) return self.incompatible_types(a, b)
} }
} }
}
self.set_a_to_b(a, b); self.set_a_to_b(a, b);
} }