fortrangoingonforty/armfortas / db1e756

Browse files

Require category+kind match in operator_arg_semantic_match

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
db1e756689a15a34744952becd44c2f013b4cf91
Parents
de70413
Tree
a158784

1 changed file

StatusFile+-
M src/ir/lower.rs 32 1
src/ir/lower.rsmodified
@@ -13069,7 +13069,38 @@ fn operator_arg_semantic_match(
1306913069
         ),
1307013070
         TypeInfo::ClassStar => matches!(actual, Some(TypeInfo::ClassStar)),
1307113071
         TypeInfo::TypeStar => matches!(actual, Some(TypeInfo::TypeStar)),
13072
-        _ => true,
13072
+        // Numeric / logical: when the actual type is known, require both
13073
+        // category (Integer/Real/Complex/Logical) and kind to agree.
13074
+        // Unknown actuals (None, e.g. an unresolved expression like
13075
+        // `reshape(...)` that didn't type-check upstream) accept anything
13076
+        // — but the dispatcher then has nothing to discriminate on, so
13077
+        // we can't fall back to wildcard-true here without picking the
13078
+        // first specific in declaration order. F2018 §10.1.5: a defined
13079
+        // operator must have an exact specific match.
13080
+        TypeInfo::Integer { kind: dk } => match actual {
13081
+            Some(TypeInfo::Integer { kind: ak }) => intrinsic_kind_matches(*dk, *ak),
13082
+            None => true,
13083
+            _ => false,
13084
+        },
13085
+        TypeInfo::Real { kind: dk } => match actual {
13086
+            Some(TypeInfo::Real { kind: ak }) => intrinsic_kind_matches(*dk, *ak),
13087
+            None => true,
13088
+            _ => false,
13089
+        },
13090
+        TypeInfo::DoublePrecision => matches!(
13091
+            actual,
13092
+            Some(TypeInfo::DoublePrecision) | Some(TypeInfo::Real { kind: Some(8) }) | None
13093
+        ),
13094
+        TypeInfo::Complex { kind: dk } => match actual {
13095
+            Some(TypeInfo::Complex { kind: ak }) => intrinsic_kind_matches(*dk, *ak),
13096
+            None => true,
13097
+            _ => false,
13098
+        },
13099
+        TypeInfo::Logical { kind: dk } => match actual {
13100
+            Some(TypeInfo::Logical { kind: ak }) => intrinsic_kind_matches(*dk, *ak),
13101
+            None => true,
13102
+            _ => false,
13103
+        },
1307313104
     }
1307413105
 }
1307513106