From 8780df8467a0eae2fa0a302574c7fce6eedb4625 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 7 Jul 2023 13:48:20 +0200 Subject: [PATCH] Correctly treat distinct inline types as having their inner type's methods available. --- src/compiler/sema_expr.c | 8 +++++ src/version.h | 2 +- .../distinct/distinct_inline_access.c3 | 32 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/distinct/distinct_inline_access.c3 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 54e37e204..25aa56836 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -3968,6 +3968,14 @@ CHECK_DEEPER: 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) { diff --git a/src/version.h b/src/version.h index 290013907..07fe19d4e 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.556" \ No newline at end of file +#define COMPILER_VERSION "0.4.557" \ No newline at end of file diff --git a/test/test_suite/distinct/distinct_inline_access.c3 b/test/test_suite/distinct/distinct_inline_access.c3 new file mode 100644 index 000000000..3b706703a --- /dev/null +++ b/test/test_suite/distinct/distinct_inline_access.c3 @@ -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; +} \ No newline at end of file