From e435b2575602c9042efd3d91c5f2fe1d7685760c Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 20 Dec 2023 18:30:44 +0800 Subject: [PATCH] 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. --- nac3core/src/typecheck/typedef/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index d275d8a..04a905d 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -789,7 +789,23 @@ impl Unifier { (TLiteral { values: val1, .. }, TLiteral { values: val2, .. }) => { for (v1, v2) in zip(val1, val2) { if v1 != v2 { - return self.incompatible_types(a, b) + let symbol_value_to_int = |value: &SymbolValue| -> Option { + 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) + } } }