Fix issue with aliasing @-macros.

This commit is contained in:
Christoffer Lerno
2022-12-05 17:38:27 +01:00
parent 44dfeb621d
commit 287de8f499
6 changed files with 78 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.105"
#define COMPILER_VERSION "0.3.106"

View 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);
}

View 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);
}

View 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);
}

View 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);
}