diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-07-15 09:27:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-15 09:27:28 +0000 |
commit | d155a54785cb7b40ada7ae748997d717a4b27ab9 (patch) | |
tree | 335a66022bc0c5b0472b5f3d98d17fc445c9adaa /gcc/rust | |
parent | ab9f7f287ef0a775ac6a504d743e20c2f5488f6f (diff) | |
parent | 95aa351e65723ce1ff9aa568523b1d5173acacf4 (diff) | |
download | gcc-d155a54785cb7b40ada7ae748997d717a4b27ab9.zip gcc-d155a54785cb7b40ada7ae748997d717a4b27ab9.tar.gz gcc-d155a54785cb7b40ada7ae748997d717a4b27ab9.tar.bz2 |
Merge #1384
1384: Support generics in check for valid types in arithmetic expressions r=philberty a=philberty
When we check for valid types we need to be sure to call destructure which
will extract out any generics so that we are checking the actual concrete
type that is being used here.
Fixes #1383
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index a5f0a84..df07cb3 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -1060,9 +1060,11 @@ private: Location expr_locus); bool - validate_arithmetic_type (TyTy::BaseType *type, + validate_arithmetic_type (const TyTy::BaseType *tyty, HIR::ArithmeticOrLogicalExpr::ExprType expr_type) { + const TyTy::BaseType *type = tyty->destructure (); + // https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators // this will change later when traits are added switch (expr_type) @@ -1078,10 +1080,10 @@ private: || (type->get_kind () == TyTy::TypeKind::USIZE) || (type->get_kind () == TyTy::TypeKind::ISIZE) || (type->get_kind () == TyTy::TypeKind::INFER - && (((TyTy::InferType *) type)->get_infer_kind () + && (((const TyTy::InferType *) type)->get_infer_kind () == TyTy::InferType::INTEGRAL)) || (type->get_kind () == TyTy::TypeKind::INFER - && (((TyTy::InferType *) type)->get_infer_kind () + && (((const TyTy::InferType *) type)->get_infer_kind () == TyTy::InferType::FLOAT)); // integers or bools @@ -1094,7 +1096,7 @@ private: || (type->get_kind () == TyTy::TypeKind::ISIZE) || (type->get_kind () == TyTy::TypeKind::BOOL) || (type->get_kind () == TyTy::TypeKind::INFER - && (((TyTy::InferType *) type)->get_infer_kind () + && (((const TyTy::InferType *) type)->get_infer_kind () == TyTy::InferType::INTEGRAL)); // integers only @@ -1105,10 +1107,12 @@ private: || (type->get_kind () == TyTy::TypeKind::USIZE) || (type->get_kind () == TyTy::TypeKind::ISIZE) || (type->get_kind () == TyTy::TypeKind::INFER - && (((TyTy::InferType *) type)->get_infer_kind () + && (((const TyTy::InferType *) type)->get_infer_kind () == TyTy::InferType::INTEGRAL)); } + gcc_unreachable (); + return false; } /* The return value of TypeCheckExpr::Resolve */ |