mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Fix implicit linking from macros when it's not valid to add dependencies.
This commit is contained in:
@@ -266,9 +266,9 @@ bool parse_module(ParseContext *c, AstId contracts)
|
||||
{
|
||||
unsigned args = vec_size(attr->exprs);
|
||||
if (args < 1) RETURN_PRINT_ERROR_AT(false, attr, "'@link' needs at least 1 argument.");
|
||||
}
|
||||
vec_add(c->unit->attr_links, attr);
|
||||
continue;
|
||||
}
|
||||
case ATTRIBUTE_IF:
|
||||
if (c->unit->if_attr) RETURN_PRINT_ERROR_AT(false, attr, "'@if' appeared more than once.");
|
||||
c->unit->if_attr = attr;
|
||||
|
||||
@@ -2571,12 +2571,13 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
|
||||
bool is_always_const = decl->func_decl.signature.attrs.always_const;
|
||||
if (decl->resolved_attributes && decl->attrs_resolved && decl->attrs_resolved->links)
|
||||
{
|
||||
Decl *func = context->call_env.current_function;
|
||||
if (!func)
|
||||
if (context->call_env.kind != CALL_ENV_FUNCTION && context->call_env.kind != CALL_ENV_FUNCTION_STATIC)
|
||||
{
|
||||
RETURN_SEMA_ERROR(call_expr, "Cannot call macro with '@links' outside of a function.");
|
||||
goto SKIP_LINK;
|
||||
}
|
||||
assert(func->resolved_attributes);
|
||||
Decl *func = context->call_env.current_function;
|
||||
ASSERT_SPAN(func, func);
|
||||
ASSERT_SPAN(func, func->resolved_attributes);
|
||||
if (!func->attrs_resolved)
|
||||
{
|
||||
func->attrs_resolved = MALLOCS(ResolvedAttrData);
|
||||
@@ -2589,6 +2590,7 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
|
||||
}
|
||||
func->attrs_resolved->links = updated;
|
||||
}
|
||||
SKIP_LINK:;
|
||||
bool is_outer = call_expr->call_expr.is_outer_call;
|
||||
ASSERT_SPAN(call_expr, decl->decl_kind == DECL_MACRO);
|
||||
|
||||
|
||||
13
test/test_suite/globals/links_global.c3
Normal file
13
test/test_suite/globals/links_global.c3
Normal file
@@ -0,0 +1,13 @@
|
||||
module test;
|
||||
import std;
|
||||
import some_module;
|
||||
|
||||
fn int main(String[] args)
|
||||
{
|
||||
int z = some_module::A_CONST{22};
|
||||
return 0;
|
||||
}
|
||||
|
||||
module some_module { F };
|
||||
import std;
|
||||
const A_CONST = 12 + 2 * math::log2(F / 25); // #error: This expression cannot be evaluated at compile time
|
||||
Reference in New Issue
Block a user