Skip to content

Commit

Permalink
Correctly treat distinct inline types as having their inner type's me…
Browse files Browse the repository at this point in the history
…thods available.
  • Loading branch information
lerno committed Jul 7, 2023
1 parent 7dc1eab commit 8780df8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/compiler/sema_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3968,6 +3968,14 @@ static inline bool sema_expr_analyse_access(SemaContext *context, Expr *expr)
goto CHECK_DEEPER;
}

if (type->type_kind == TYPE_DISTINCT && decl->is_substruct)
{
Expr *inner_expr = expr_copy(current_parent);
type = type->decl->distinct_decl.base_type;
inner_expr->type = type;
current_parent = inner_expr;
goto CHECK_DEEPER;
}
// 11b. Otherwise we give up.
if (private)
{
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define COMPILER_VERSION "0.4.556"
#define COMPILER_VERSION "0.4.557"
32 changes: 32 additions & 0 deletions test/test_suite/distinct/distinct_inline_access.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module testing;
import std::io;
import foo;

fn void main()
{
FooInt foo;
}

def FooInt = distinct inline Foo;

struct Bar
{
FooInt list;
}

fn void Bar.set(&self, int x)
{
self.list.set(x);
}

module foo;

struct Foo
{
int x;
}

fn void Foo.set(&self, int x)
{
self.x = x;
}

0 comments on commit 8780df8

Please sign in to comment.