summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir/expr.hpp1
-rw-r--r--src/hir/from_ast_expr.cpp11
-rw-r--r--src/hir/type.hpp4
-rw-r--r--src/hir_typeck/expr_cs.cpp30
-rw-r--r--src/hir_typeck/expr_simple.cpp2
-rw-r--r--src/hir_typeck/helpers.cpp1
6 files changed, 44 insertions, 5 deletions
diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp
index 300414b4..90ad27a7 100644
--- a/src/hir/expr.hpp
+++ b/src/hir/expr.hpp
@@ -548,6 +548,7 @@ struct ExprNode_PathValue:
enum Target {
UNKNOWN,
FUNCTION,
+ STRUCT_CONSTR,
STATIC,
CONSTANT,
};
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp
index a25fe7ae..d1f7e16e 100644
--- a/src/hir/from_ast_expr.cpp
+++ b/src/hir/from_ast_expr.cpp
@@ -555,7 +555,16 @@ struct LowerHIR_ExprNode_Visitor:
m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::UNKNOWN ) );
),
(Struct,
- m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) );
+ // TODO: Check the form and emit a PathValue if not a unit
+ if( e.struct_->m_data.is_Struct() ) {
+ // ERROR.
+ }
+ else if( e.struct_->m_data.as_Tuple().ents.size() > 0 ) {
+ m_rv.reset( new ::HIR::ExprNode_PathValue( v.span(), LowerHIR_Path(Span(v.get_pos()), v.m_path), ::HIR::ExprNode_PathValue::STRUCT_CONSTR ) );
+ }
+ else {
+ m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), true ) );
+ }
),
(EnumVar,
m_rv.reset( new ::HIR::ExprNode_UnitVariant( v.span(), LowerHIR_GenericPath(Span(v.get_pos()), v.m_path), false ) );
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 4f495fcd..549bf837 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -181,8 +181,8 @@ public:
TypeRef(::HIR::CoreType ct):
m_data( Data::make_Primitive(mv$(ct)) )
{}
- TypeRef(::HIR::Path p):
- m_data( Data::make_Path( {mv$(p), TypePathBinding()} ) )
+ TypeRef(::HIR::Path p, TypePathBinding pb=TypePathBinding()):
+ m_data( Data::make_Path( {mv$(p), mv$(pb)} ) )
{}
static TypeRef new_unit() {
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 8e186bd6..8d2afe33 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -908,6 +908,8 @@ namespace {
{
TRACE_FUNCTION_F(&node << " " << node.m_path << " [" << (node.m_is_struct ? "struct" : "enum") << "]");
+ // TODO: Check?
+
// - Create ivars in path, and set result type
const auto ty = this->get_structenum_ty(node.span(), node.m_is_struct, node.m_path);
this->context.equate_types(node.span(), node.m_res_type, ty);
@@ -1107,14 +1109,38 @@ namespace {
BUG(sp, "Unknown target PathValue encountered with Generic path");
case ::HIR::ExprNode_PathValue::FUNCTION: {
const auto& f = this->context.m_crate.get_function_by_path(sp, e.m_path);
+ fix_param_count(sp, this->context, e, f.m_params, e.m_params);
+
::HIR::FunctionType ft {
f.m_unsafe,
f.m_abi,
- box$( f.m_return.clone() ),
+ box$( monomorphise_type(sp, f.m_params, e.m_params, f.m_return) ),
{}
};
for( const auto& arg : f.m_args )
- ft.m_arg_types.push_back( arg.second.clone() );
+ {
+ ft.m_arg_types.push_back( monomorphise_type(sp, f.m_params, e.m_params, arg.second) );
+ }
+
+ auto ty = ::HIR::TypeRef( ::HIR::TypeRef::Data::make_Function(mv$(ft)) );
+ this->context.equate_types(sp, node.m_res_type, ty);
+ } break;
+ case ::HIR::ExprNode_PathValue::STRUCT_CONSTR: {
+ const auto& s = this->context.m_crate.get_struct_by_path(sp, e.m_path);
+ const auto& se = s.m_data.as_Tuple();
+ fix_param_count(sp, this->context, e, s.m_params, e.m_params);
+
+ ::HIR::FunctionType ft {
+ false,
+ "rust",
+ box$( ::HIR::TypeRef( node.m_path.clone(), ::HIR::TypeRef::TypePathBinding::make_Struct(&s) ) ),
+ {}
+ };
+ for( const auto& arg : se )
+ {
+ ft.m_arg_types.push_back( monomorphise_type(sp, s.m_params, e.m_params, arg.ent) );
+ }
+
auto ty = ::HIR::TypeRef( ::HIR::TypeRef::Data::make_Function(mv$(ft)) );
this->context.equate_types(sp, node.m_res_type, ty);
} break;
diff --git a/src/hir_typeck/expr_simple.cpp b/src/hir_typeck/expr_simple.cpp
index e4406fb7..c4fdfdbf 100644
--- a/src/hir_typeck/expr_simple.cpp
+++ b/src/hir_typeck/expr_simple.cpp
@@ -1654,6 +1654,8 @@ namespace typeck {
switch(node.m_target) {
case ::HIR::ExprNode_PathValue::UNKNOWN:
BUG(sp, "Unknown target PathValue encountered with Generic path");
+ case ::HIR::ExprNode_PathValue::STRUCT_CONSTR:
+ TODO(sp, "STRUCT_CONSTR");
case ::HIR::ExprNode_PathValue::FUNCTION: {
const auto& f = this->context.m_crate.get_function_by_path(sp, e.m_path);
::HIR::FunctionType ft {
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index e9d2d754..546221f6 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -232,6 +232,7 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl)
::HIR::TypeRef monomorphise_type(const Span& sp, const ::HIR::GenericParams& params_def, const ::HIR::PathParams& params, const ::HIR::TypeRef& tpl)
{
DEBUG("tpl = " << tpl);
+ ASSERT_BUG(sp, params.m_types.size() == params_def.m_types.size(), "Parameter count mismatch - exp " << params_def.m_types.size() << ", got " << params.m_types.size());
return monomorphise_type_with(sp, tpl, [&](const auto& gt)->const auto& {
const auto& e = gt.m_data.as_Generic();
if( e.name == "Self" )