summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-11-22 21:57:59 +0800
committerJohn Hodge <tpg@mutabah.net>2016-11-22 21:57:59 +0800
commitf459cf31501bba8d61e34a2850023dccf57e2466 (patch)
treef8cfa638f4aeeea6135ddcbccdca94d969fea185 /src
parent91fc04283896d0db76f601228bd202bcd0291b17 (diff)
downloadmrust-f459cf31501bba8d61e34a2850023dccf57e2466.tar.gz
Resolve Absolute - Search value scope for tuple struct patterns
Diffstat (limited to 'src')
-rw-r--r--src/hir/from_ast.cpp15
-rw-r--r--src/resolve/absolute.cpp2
2 files changed, 14 insertions, 3 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 44b7b21c..f03f2000 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -258,9 +258,13 @@
assert( pb.struct_ || pb.hir );
unsigned int field_count;
if( pb.struct_ ) {
+ if( !pb.struct_->m_data.is_Tuple() )
+ ERROR(pat.span(), E0000, "Tuple struct pattern on non-tuple struct - " << e.path);
field_count = pb.struct_->m_data.as_Tuple().ents.size();
}
else {
+ if( !pb.hir->m_data.is_Tuple() )
+ ERROR(pat.span(), E0000, "Tuple struct pattern on non-tuple struct - " << e.path);
field_count = pb.hir->m_data.as_Tuple().size();
}
::std::vector<HIR::Pattern> sub_patterns;
@@ -1177,16 +1181,20 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
)
}
+ Span mod_span;
for( const auto& ie : ast_mod.m_namespace_items )
{
+ const auto& sp = mod_span;
if( ie.second.is_import ) {
- auto hir_path = LowerHIR_SimplePath( Span(), ie.second.path );
+ auto hir_path = LowerHIR_SimplePath( sp, ie.second.path );
::HIR::TypeItem ti;
TU_MATCH_DEF( ::AST::PathBinding, (ie.second.path.binding()), (pb),
(
+ DEBUG("Import NS " << ie.first << " = " << hir_path);
ti = ::HIR::TypeItem::make_Import({ mv$(hir_path), false, 0 });
),
(EnumVar,
+ DEBUG("Import NS " << ie.first << " = " << hir_path << " (Enum Variant)");
ti = ::HIR::TypeItem::make_Import({ mv$(hir_path), true, pb.idx });
)
)
@@ -1195,15 +1203,18 @@ void _add_mod_val_item(::HIR::Module& mod, ::std::string name, bool is_pub, ::H
}
for( const auto& ie : ast_mod.m_value_items )
{
+ const auto& sp = mod_span;
if( ie.second.is_import ) {
- auto hir_path = LowerHIR_SimplePath( Span(), ie.second.path );
+ auto hir_path = LowerHIR_SimplePath( sp, ie.second.path );
::HIR::ValueItem vi;
TU_MATCH_DEF( ::AST::PathBinding, (ie.second.path.binding()), (pb),
(
+ DEBUG("Import VAL " << ie.first << " = " << hir_path);
vi = ::HIR::ValueItem::make_Import({ mv$(hir_path), false, 0 });
),
(EnumVar,
+ DEBUG("Import VAL " << ie.first << " = " << hir_path << " (Enum Variant)");
vi = ::HIR::ValueItem::make_Import({ mv$(hir_path), true, pb.idx });
)
)
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index fd451ca5..0b9c2476 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -1774,7 +1774,7 @@ void Resolve_Absolute_Pattern(Context& context, bool allow_refutable, ::AST::Pa
Resolve_Absolute_Pattern(context, allow_refutable, sp);
),
(StructTuple,
- Resolve_Absolute_Path(context, pat.span(), Context::LookupMode::Pattern, e.path);
+ Resolve_Absolute_Path(context, pat.span(), Context::LookupMode::Constant, e.path);
for(auto& sp : e.tup_pat.start)
Resolve_Absolute_Pattern(context, allow_refutable, sp);
for(auto& sp : e.tup_pat.end)