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

View File

@ -789,7 +789,23 @@ 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 {
return self.incompatible_types(a, b) 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)
}
} }
} }