mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Clearer errors when using a &ref parameter with type.
This commit is contained in:
@@ -1443,11 +1443,6 @@ bool parse_parameters(ParseContext *c, Decl ***params_ref, Variadic *variadic, i
|
||||
PRINT_ERROR_LAST("'&foo' parameters may not be followed by '...’");
|
||||
return false;
|
||||
}
|
||||
if (type)
|
||||
{
|
||||
PRINT_ERROR_LAST("'&foo' should be untyped.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Span includes the "&"
|
||||
span = extend_span_with_token(span, c->span);
|
||||
|
||||
@@ -1145,6 +1145,15 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig,
|
||||
if (!sema_resolve_type_info(context, method_parent,
|
||||
is_macro ? RESOLVE_TYPE_MACRO_METHOD : RESOLVE_TYPE_FUNC_METHOD)) return false;
|
||||
}
|
||||
|
||||
if (params && params[0] && params[0]->var.self_addr && params[0]->var.type_info)
|
||||
{
|
||||
if (method_parent)
|
||||
{
|
||||
RETURN_SEMA_ERROR(type_infoptr(params[0]->var.type_info), "A ref parameter should always be untyped, please remove the type here.");
|
||||
}
|
||||
RETURN_SEMA_ERROR(params[0], "Ref parameters are only allowed on methods.");
|
||||
}
|
||||
// Fill in the type if the first parameter is lacking a type.
|
||||
if (method_parent && params && params[0] && !params[0]->var.type_info)
|
||||
{
|
||||
|
||||
9
test/test_suite/functions/ref_param_fn.c3
Normal file
9
test/test_suite/functions/ref_param_fn.c3
Normal file
@@ -0,0 +1,9 @@
|
||||
fn String str(int& element) // #error: A ref parameter should always be untyped
|
||||
{
|
||||
return "abc";
|
||||
}
|
||||
|
||||
fn String int.str(int& element) // #error: Ref parameters are only allowed on methods
|
||||
{
|
||||
return "abc";
|
||||
}
|
||||
Reference in New Issue
Block a user