summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir/from_ast_expr.cpp5
-rw-r--r--src/hir_conv/expand_type.cpp27
2 files changed, 25 insertions, 7 deletions
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp
index b0ea4169..21024dd7 100644
--- a/src/hir/from_ast_expr.cpp
+++ b/src/hir/from_ast_expr.cpp
@@ -252,6 +252,9 @@ struct LowerHIR_ExprNode_Visitor:
mv$( args )
) );
),
+ (TypeAlias,
+ TODO(v.span(), "CallPath -> TupleVariant TypeAlias");
+ ),
(EnumVar,
m_rv.reset( new ::HIR::ExprNode_TupleVariant( v.span(),
LowerHIR_GenericPath(v.span(), v.m_path), false,
@@ -539,7 +542,7 @@ struct LowerHIR_ExprNode_Visitor:
values.push_back( ::std::make_pair(val.first, LowerHIR_ExprNode_Inner(*val.second)) );
m_rv.reset( new ::HIR::ExprNode_StructLiteral( v.span(),
LowerHIR_GenericPath(v.get_pos(), v.m_path),
- v.m_path.binding().is_Struct(),
+ ! v.m_path.binding().is_EnumVar(),
LowerHIR_ExprNode_Inner_Opt(v.m_base_value.get()),
mv$(values)
) );
diff --git a/src/hir_conv/expand_type.cpp b/src/hir_conv/expand_type.cpp
index c176aa71..f2565954 100644
--- a/src/hir_conv/expand_type.cpp
+++ b/src/hir_conv/expand_type.cpp
@@ -105,7 +105,7 @@ public:
}
- ::HIR::GenericPath expand_alias_pattern(const Span& sp, const ::HIR::GenericPath& path)
+ ::HIR::GenericPath expand_alias_gp(const Span& sp, const ::HIR::GenericPath& path)
{
const unsigned int MAX_RECURSIVE_TYPE_EXPANSIONS = 100;
@@ -118,10 +118,10 @@ public:
if( ty == ::HIR::TypeRef() )
break ;
if( !ty.m_data.is_Path() )
- ERROR(sp, E0000, "Type alias referenced in pattern doesn't point to a path");
+ ERROR(sp, E0000, "Type alias referenced in generic path doesn't point to a path");
auto& ty_p = ty.m_data.as_Path().path;
if( !ty_p.m_data.is_Generic() )
- ERROR(sp, E0000, "Type alias referenced in pattern doesn't point to a generic path");
+ ERROR(sp, E0000, "Type alias referenced in generic path doesn't point to a generic path");
rv = mv$( ty_p.m_data.as_Generic() );
this->visit_generic_path(rv, ::HIR::Visitor::PathContext::TYPE);
@@ -141,7 +141,7 @@ public:
(
),
(StructValue,
- auto new_path = expand_alias_pattern(sp, e.path);
+ auto new_path = expand_alias_gp(sp, e.path);
if( new_path.m_path.m_components.size() != 0 )
{
DEBUG("Replacing " << e.path << " with " << new_path);
@@ -149,7 +149,7 @@ public:
}
),
(StructTuple,
- auto new_path = expand_alias_pattern(sp, e.path);
+ auto new_path = expand_alias_gp(sp, e.path);
if( new_path.m_path.m_components.size() != 0 )
{
DEBUG("Replacing " << e.path << " with " << new_path);
@@ -157,7 +157,7 @@ public:
}
),
(Struct,
- auto new_path = expand_alias_pattern(sp, e.path);
+ auto new_path = expand_alias_gp(sp, e.path);
if( new_path.m_path.m_components.size() != 0 )
{
DEBUG("Replacing " << e.path << " with " << new_path);
@@ -211,6 +211,21 @@ public:
::HIR::ExprVisitorDef::visit(node);
}
+ void visit(::HIR::ExprNode_StructLiteral& node) override
+ {
+ if( node.m_is_struct )
+ {
+ auto new_path = upper_visitor.expand_alias_gp(node.span(), node.m_path);
+ if( new_path.m_path.m_components.size() != 0 )
+ {
+ DEBUG("Replacing " << node.m_path << " with " << new_path);
+ node.m_path = mv$(new_path);
+ }
+ }
+
+ ::HIR::ExprVisitorDef::visit(node);
+ }
+
void visit(::HIR::ExprNode_Match& node) override
{
for(auto& arm : node.m_arms) {