- @test/@benchmark on module would attach to interface and regular methods.

This commit is contained in:
Christoffer Lerno
2025-08-28 00:28:32 +02:00
parent 239d249f01
commit 90d3f429aa
5 changed files with 26 additions and 3 deletions

View File

@@ -81,6 +81,7 @@
- Fix alignment on jump table.
- Fix correct `?` after optional function name when reporting type errors.
- Make `log` and `exp` no-strip.
- `@test`/`@benchmark` on module would attach to interface and regular methods.
### Stdlib changes
- Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`.

View File

@@ -1225,8 +1225,12 @@ PARSE_EXPR:
static bool parse_attributes_for_global(ParseContext *c, Decl *decl)
{
Visibility visibility = c->unit->default_visibility;
if (decl->decl_kind == DECL_FUNC) decl->func_decl.attr_test = c->unit->test_by_default;
if (decl->decl_kind == DECL_FUNC) decl->func_decl.attr_benchmark = c->unit->benchmark_by_default;
// Transfer the test / benchmark properties
if (decl->decl_kind == DECL_FUNC && !decl->func_decl.attr_interface_method && !decl->func_decl.type_parent)
{
decl->func_decl.attr_test = c->unit->test_by_default;
decl->func_decl.attr_benchmark = c->unit->benchmark_by_default;
}
decl->is_export = c->unit->export_by_default;
bool is_builtin = false;
bool is_cond;
@@ -2692,6 +2696,7 @@ static inline Decl *parse_func_definition(ParseContext *c, AstId contracts, Func
Decl *func = decl_calloc();
func->decl_kind = DECL_FUNC;
func->func_decl.docs = contracts;
func->func_decl.attr_interface_method = parse_kind == FUNC_PARSE_INTERFACE;
if (!parse_func_macro_header(c, func)) return poisoned_decl;
if (func->name[0] == '@')
{

View File

@@ -954,7 +954,6 @@ static bool sema_analyse_interface(SemaContext *context, Decl *decl, bool *erase
SEMA_ERROR(type_infoptr(method->func_decl.type_parent), "Interfaces should not be declared as methods.");
return decl_poison(method);
}
method->func_decl.attr_interface_method = true;
bool erase = false;
// Insert the first parameter, which is the implicit `void*`

View File

@@ -0,0 +1,18 @@
module test;
import std;
fn int main()
{
return 0;
}
module foo @test;
interface Bob
{
fn void test();
}
struct Foo
{
int a;
}
fn void Foo.test(&self) {}