mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix issue with aliasing @-macros.
This commit is contained in:
@@ -1747,7 +1747,7 @@ static inline Decl *parse_define_ident(ParseContext *c, Visibility visibility)
|
||||
// 2. At this point we expect an ident or a const token.
|
||||
// since the Type is handled.
|
||||
TokenType alias_type = c->tok;
|
||||
if (alias_type != TOKEN_IDENT && alias_type != TOKEN_CONST_IDENT)
|
||||
if (alias_type != TOKEN_IDENT && alias_type != TOKEN_CONST_IDENT && alias_type != TOKEN_AT_IDENT)
|
||||
{
|
||||
if (token_is_any_type(alias_type))
|
||||
{
|
||||
@@ -1799,6 +1799,16 @@ static inline Decl *parse_define_ident(ParseContext *c, Visibility visibility)
|
||||
SEMA_ERROR_HERE("Expected a constant name here.");
|
||||
return poisoned_decl;
|
||||
}
|
||||
if (alias_type == TOKEN_IDENT && c->tok == TOKEN_AT_IDENT)
|
||||
{
|
||||
SEMA_ERROR(decl, "A name with '@' prefix cannot be aliased to a name without '@', try adding a '@' before '%s'.", decl->name);
|
||||
return poisoned_decl;
|
||||
}
|
||||
if (alias_type == TOKEN_AT_IDENT && c->tok == TOKEN_IDENT)
|
||||
{
|
||||
SEMA_ERROR(decl, "An alias cannot use '@' if the aliased identifier doesn't, please remove the '@' symbol.");
|
||||
return poisoned_decl;
|
||||
}
|
||||
SEMA_ERROR_HERE("Expected a function or variable name here.");
|
||||
return poisoned_decl;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.3.105"
|
||||
#define COMPILER_VERSION "0.3.106"
|
||||
17
test/test_suite/define/test_at.c3
Normal file
17
test/test_suite/define/test_at.c3
Normal file
@@ -0,0 +1,17 @@
|
||||
module foo<Type>;
|
||||
import std::io;
|
||||
|
||||
macro @hello(Type thing) {
|
||||
io::printfln("%d", $sizeof(thing));
|
||||
}
|
||||
|
||||
module bar;
|
||||
|
||||
import private foo;
|
||||
|
||||
define intHello = foo::@hello<int>; // #error: cannot be aliased
|
||||
define @intHello = foo::hello<int>; // #error: cannot use
|
||||
|
||||
fn void main(char[][] args) {
|
||||
@intHello(42);
|
||||
}
|
||||
16
test/test_suite/define/test_at_alias.c3
Normal file
16
test/test_suite/define/test_at_alias.c3
Normal file
@@ -0,0 +1,16 @@
|
||||
module foo<Type>;
|
||||
import std::io;
|
||||
|
||||
macro @hello(Type thing) {
|
||||
io::printfln("%d", $sizeof(thing));
|
||||
}
|
||||
|
||||
module bar;
|
||||
|
||||
import private foo;
|
||||
|
||||
define @intHello = foo::@hello<int>;
|
||||
|
||||
fn void main(char[][] args) {
|
||||
@intHello(42);
|
||||
}
|
||||
17
test/test_suite2/define/test_at.c3
Normal file
17
test/test_suite2/define/test_at.c3
Normal file
@@ -0,0 +1,17 @@
|
||||
module foo<Type>;
|
||||
import std::io;
|
||||
|
||||
macro @hello(Type thing) {
|
||||
io::printfln("%d", $sizeof(thing));
|
||||
}
|
||||
|
||||
module bar;
|
||||
|
||||
import private foo;
|
||||
|
||||
define intHello = foo::@hello<int>; // #error: cannot be aliased
|
||||
define @intHello = foo::hello<int>; // #error: cannot use
|
||||
|
||||
fn void main(char[][] args) {
|
||||
@intHello(42);
|
||||
}
|
||||
16
test/test_suite2/define/test_at_alias.c3
Normal file
16
test/test_suite2/define/test_at_alias.c3
Normal file
@@ -0,0 +1,16 @@
|
||||
module foo<Type>;
|
||||
import std::io;
|
||||
|
||||
macro @hello(Type thing) {
|
||||
io::printfln("%d", $sizeof(thing));
|
||||
}
|
||||
|
||||
module bar;
|
||||
|
||||
import private foo;
|
||||
|
||||
define @intHello = foo::@hello<int>;
|
||||
|
||||
fn void main(char[][] args) {
|
||||
@intHello(42);
|
||||
}
|
||||
Reference in New Issue
Block a user