mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Reference macro parameters syntax does not error in certain cases. #2612
This commit is contained in:
@@ -48,6 +48,7 @@
|
|||||||
- Bug on rethrow in return with defer #2603.
|
- Bug on rethrow in return with defer #2603.
|
||||||
- Fix bug when converting from vector to distinct type of wider vector. #2604
|
- Fix bug when converting from vector to distinct type of wider vector. #2604
|
||||||
- `$defined(hashmap.init(mem))` causes compiler segfault #2611.
|
- `$defined(hashmap.init(mem))` causes compiler segfault #2611.
|
||||||
|
- Reference macro parameters syntax does not error in certain cases. #2612
|
||||||
|
|
||||||
### Stdlib changes
|
### Stdlib changes
|
||||||
- Add `CGFloat` `CGPoint` `CGSize` `CGRect` types to core_foundation (macOS).
|
- Add `CGFloat` `CGPoint` `CGSize` `CGRect` types to core_foundation (macOS).
|
||||||
|
|||||||
@@ -1639,7 +1639,7 @@ CHECK_ELLIPSIS:
|
|||||||
}
|
}
|
||||||
if (vec_size(params) > 0)
|
if (vec_size(params) > 0)
|
||||||
{
|
{
|
||||||
PRINT_ERROR_HERE("Only the first parameter may use '&'.");
|
PRINT_ERROR_HERE("Only the first parameter may be a self parameter using '&'.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// This will catch Type... &foo and &foo..., neither is allowed.
|
// This will catch Type... &foo and &foo..., neither is allowed.
|
||||||
|
|||||||
@@ -1204,13 +1204,16 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig,
|
|||||||
is_macro ? RESOLVE_TYPE_MACRO_METHOD : RESOLVE_TYPE_FUNC_METHOD)) return false;
|
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 (params && params[0] && params[0]->var.self_addr)
|
||||||
{
|
{
|
||||||
if (method_parent)
|
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], "Self parameters are only allowed on methods.");
|
||||||
|
}
|
||||||
|
if (params[0]->var.type_info)
|
||||||
|
{
|
||||||
|
RETURN_SEMA_ERROR(type_infoptr(params[0]->var.type_info), "A self 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.
|
// Fill in the type if the first parameter is lacking a type.
|
||||||
if (method_parent && params && params[0] && !params[0]->var.type_info)
|
if (method_parent && params && params[0] && !params[0]->var.type_info)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
fn String str(int& element) // #error: Ref parameters are only allowed on methods
|
fn String str(int& element) // #error: Self parameters are only allowed on methods
|
||||||
{
|
{
|
||||||
return "abc";
|
return "abc";
|
||||||
}
|
}
|
||||||
|
|
||||||
fn String int.str(int& element) // #error: A ref parameter should always be untyped
|
fn String int.str(int& element) // #error: A self parameter should always be untyped, please remove the type here
|
||||||
{
|
{
|
||||||
return "abc";
|
return "abc";
|
||||||
}
|
}
|
||||||
|
|||||||
11
test/test_suite/methods/self_not_method.c3
Normal file
11
test/test_suite/methods/self_not_method.c3
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
macro void m(&x) // #error: Self parameters are only allowed on methods
|
||||||
|
{
|
||||||
|
$echo $typeof(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn void main()
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
m(x);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user