Description
fn square(num: i32) -> _ {
num * num
}
fn main() {
square(123);
}
gives:
[...]: error: type annotations needed
6 | square(123);
| ^
We should check for inference variables where they are not supported (ie behind a TvVar) rustc gives:
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> <source>:1:24
|
1 | fn square(num: i32) -> _ {
| ^
| |
| not allowed in type signatures
| help: replace with the correct return type: `i32`
Guide
Check for inference variables on return types of Functions:
- Add helper is_inference_var() which returns if the TypeKind == Infer
gccrs/gcc/rust/typecheck/rust-tyty.h
Line 216 in 28f527c
- Add is general inference variable helper which asserts it iis_inference_var casts over and checks the infer type kind
gccrs/gcc/rust/typecheck/rust-tyty.h
Line 216 in 28f527c
-
gccrs/gcc/rust/typecheck/rust-hir-type-check-toplevel.h
Lines 259 to 296 in 28f527c
-
gccrs/gcc/rust/typecheck/rust-hir-type-check-implitem.h
Lines 78 to 123 in 28f527c
-
gccrs/gcc/rust/typecheck/rust-hir-type-check-implitem.h
Lines 194 to 211 in 28f527c
You can check for an inference variable with:
TyTy::BaseType* return_type = ...;
bool is_inference_variable = return_type->get_kind() == TyTy::TypeKind::INFER;
TyTy::InferType* infer_var = static_cast<TyTy::InferType*>(infer_var);
bool is_general_inference_variable = infer_var->get_infer_kind() == TyTy::InferType::InferTypeKind::GENERAL;
Inference variables are of 3 kinds:
- general which means it can be anything
- integer the type is some kind of integer which will default to i32
- float the type is some kind of decimal value default f64
We should error for any general inference variable, but maybe even if it is just any kind of inference variable.
Metadata
Metadata
Assignees
Type
Projects
Status