1154: Add support for isize and usize type-hints r=philberty a=philberty

This bug turned out to be that we expected a usize for the array capacity
but the specified capacity turned out to be an integer inference variable
which will default to a signed integer. The type resolution was missing
handling the type-hints of isize and usize

Fixes #1152


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
This commit is contained in:
bors[bot] 2022-04-22 11:45:59 +00:00 committed by GitHub
commit b392376cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -133,6 +133,14 @@ TypeCheckBase::resolve_literal (const Analysis::NodeMapping &expr_mappings,
ok = context->lookup_builtin ("f64", &infered);
break;
case CORETYPE_ISIZE:
ok = context->lookup_builtin ("isize", &infered);
break;
case CORETYPE_USIZE:
ok = context->lookup_builtin ("usize", &infered);
break;
default:
ok = true;
infered

View File

@ -619,6 +619,8 @@ public:
= (negated_expr_ty->get_kind () == TyTy::TypeKind::INT)
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::UINT)
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::FLOAT)
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::ISIZE)
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::USIZE)
|| (negated_expr_ty->get_kind () == TyTy::TypeKind::INFER
&& (((TyTy::InferType *) negated_expr_ty)->get_infer_kind ()
== TyTy::InferType::INTEGRAL))

View File

@ -0,0 +1,8 @@
fn test() {
let f = [0; -4_isize];
// { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
// { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
let f = [0_usize; -1_isize];
// { dg-error "expected .usize. got .isize." "" { target *-*-* } .-1 }
// { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
}