Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kurtenacker committed Oct 16, 2024
2 parents af38e89 + e0fd7c9 commit b9a39d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 1 addition & 3 deletions include/artic/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,7 @@ struct TypeApp : public Type {
}

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

void print(Printer&) const override;
bool equals(const Type*) const override;
Expand Down
9 changes: 8 additions & 1 deletion src/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,13 @@ bool TypeChecker::check_filter(const ast::Expr& expr) {
is_mutable = true;
else
return true;
} else if (expr.isa<ast::LiteralExpr>())
} else if (expr.isa<ast::LiteralExpr>()) {
return true;
} else if (auto proj = expr.isa<ast::ProjExpr>()) {
//This needs to be supported to inspect struct and tuple members.
//TODO: Not sure if this check coveres all possible problematic cases.
return check_filter(*proj->expr);
}

error(expr.loc, "unsupported expression in filter");
if (is_logic_or)
Expand Down Expand Up @@ -703,6 +708,8 @@ const artic::Type* Path::infer(TypeChecker& checker, bool value_expected, Ptr<Ex
if (enum_type->decl.options[*index]->struct_type) {
// If the enumeration option uses the record syntax, we use the corresponding structure type
type = enum_type->decl.options[*index]->struct_type;
if (type_app)
type = checker.type_table.type_app(type->as<StructType>(), type_app->type_args);
is_value = false;
is_ctor = true;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ const ModType::Members& ModType::members() const {
return *members_;
}

const Type* TypeApp::member_type(size_t i) const {
if (auto enum_t = applied->isa<EnumType>(); enum_t && enum_t->decl.options[i]->struct_type)
return type_table.type_app(enum_t->decl.options[i]->struct_type->as<StructType>(), type_args);
return applied->as<ComplexType>()->member_type(i)->replace(replace_map());
}

// Misc. ---------------------------------------------------------------------------

bool Type::subtype(const Type* other) const {
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ add_test(NAME simple_enums1 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURC
add_test(NAME simple_enums2 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums2.art)
add_test(NAME simple_enums3 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums3.art)
add_test(NAME simple_enums4 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums4.art)
add_test(NAME simple_enums5 COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/enums5.art)
add_test(NAME simple_types COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/types.art)
add_test(NAME simple_loops COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/loops.art)
add_test(NAME simple_return COMMAND artic --print-ast ${CMAKE_CURRENT_SOURCE_DIR}/simple/return.art)
Expand Down Expand Up @@ -157,7 +158,7 @@ if (Thorin_HAS_LLVM_SUPPORT)
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

if (NOT TARGET clang)
find_package(Clang REQUIRED CONFIG PATHS ${LLVM_DIR}/../clang NO_DEFAULT_PATH)
find_package(Clang REQUIRED CONFIG PATHS ${LLVM_DIR}/../clang)
endif()

# Compile the helper functions into an object file
Expand Down
14 changes: 14 additions & 0 deletions test/simple/enums5.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum G[T] { A, B(bool), C { x: bool, y: T }, D {} }
#[export]
fn woah(k: G[i32]) {
match k {
G[i32]::A => 1,
G[i32]::B(true) => 3,
G[i32]::B(false) => 4,
G[i32]::C { x = true, y = 1 } => 5,
G[i32]::C { x = true, y = _ } => 6,
G[i32]::C { x = false, y = 2 } => 7,
G[i32]::C { x = false, y = _ } => 8,
G[i32]::D {} => 9
}
}

0 comments on commit b9a39d4

Please sign in to comment.