Skip to content

Commit b9a39d4

Browse files
committed
Merge branch 'master' into development
2 parents af38e89 + e0fd7c9 commit b9a39d4

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

include/artic/types.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,7 @@ struct TypeApp : public Type {
594594
}
595595

596596
/// Returns the type of the given member of the applied type, if it is a complex type.
597-
const Type* member_type(size_t i) const {
598-
return applied->as<ComplexType>()->member_type(i)->replace(replace_map());
599-
}
597+
const Type* member_type(size_t i) const;
600598

601599
void print(Printer&) const override;
602600
bool equals(const Type*) const override;

src/check.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,13 @@ bool TypeChecker::check_filter(const ast::Expr& expr) {
422422
is_mutable = true;
423423
else
424424
return true;
425-
} else if (expr.isa<ast::LiteralExpr>())
425+
} else if (expr.isa<ast::LiteralExpr>()) {
426426
return true;
427+
} else if (auto proj = expr.isa<ast::ProjExpr>()) {
428+
//This needs to be supported to inspect struct and tuple members.
429+
//TODO: Not sure if this check coveres all possible problematic cases.
430+
return check_filter(*proj->expr);
431+
}
427432

428433
error(expr.loc, "unsupported expression in filter");
429434
if (is_logic_or)
@@ -703,6 +708,8 @@ const artic::Type* Path::infer(TypeChecker& checker, bool value_expected, Ptr<Ex
703708
if (enum_type->decl.options[*index]->struct_type) {
704709
// If the enumeration option uses the record syntax, we use the corresponding structure type
705710
type = enum_type->decl.options[*index]->struct_type;
711+
if (type_app)
712+
type = checker.type_table.type_app(type->as<StructType>(), type_app->type_args);
706713
is_value = false;
707714
is_ctor = true;
708715
} else {

src/types.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ const ModType::Members& ModType::members() const {
476476
return *members_;
477477
}
478478

479+
const Type* TypeApp::member_type(size_t i) const {
480+
if (auto enum_t = applied->isa<EnumType>(); enum_t && enum_t->decl.options[i]->struct_type)
481+
return type_table.type_app(enum_t->decl.options[i]->struct_type->as<StructType>(), type_args);
482+
return applied->as<ComplexType>()->member_type(i)->replace(replace_map());
483+
}
484+
479485
// Misc. ---------------------------------------------------------------------------
480486

481487
bool Type::subtype(const Type* other) const {

test/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ add_test(NAME simple_enums1 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURC
4747
add_test(NAME simple_enums2 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums2.art)
4848
add_test(NAME simple_enums3 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums3.art)
4949
add_test(NAME simple_enums4 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums4.art)
50+
add_test(NAME simple_enums5 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums5.art)
5051
add_test(NAME simple_types COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/types.art)
5152
add_test(NAME simple_loops COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/loops.art)
5253
add_test(NAME simple_return COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/return.art)
@@ -157,7 +158,7 @@ if (Thorin_HAS_LLVM_SUPPORT)
157158
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
158159

159160
if (NOT TARGET clang)
160-
find_package(Clang REQUIRED CONFIG PATHS ${LLVM_DIR}/../clang NO_DEFAULT_PATH)
161+
find_package(Clang REQUIRED CONFIG PATHS ${LLVM_DIR}/../clang)
161162
endif()
162163

163164
# Compile the helper functions into an object file

test/simple/enums5.art

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enum G[T] { A, B(bool), C { x: bool, y: T }, D {} }
2+
#[export]
3+
fn woah(k: G[i32]) {
4+
match k {
5+
G[i32]::A => 1,
6+
G[i32]::B(true) => 3,
7+
G[i32]::B(false) => 4,
8+
G[i32]::C { x = true, y = 1 } => 5,
9+
G[i32]::C { x = true, y = _ } => 6,
10+
G[i32]::C { x = false, y = 2 } => 7,
11+
G[i32]::C { x = false, y = _ } => 8,
12+
G[i32]::D {} => 9
13+
}
14+
}

0 commit comments

Comments
 (0)