From 303d0a93372281c471e450a7c6938ab2600d5e14 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 24 Mar 2015 23:24:28 +0800 Subject: resolve "if let", remove tiny bit of typecheck in path lookup --- src/ast/ast.cpp | 2 +- src/ast/path.cpp | 16 ++++++++-------- src/convert/resolve.cpp | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index 7d0637ac..5559a4d8 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -495,7 +495,7 @@ template typename ::std::vector >::const_iterator find_named(const ::std::vector >& vec, const ::std::string& name) { return ::std::find_if(vec.begin(), vec.end(), [&name](const Item& x) { - DEBUG("find_named - x.name = " << x.name); + //DEBUG("find_named - x.name = " << x.name); return x.name == name; }); } diff --git a/src/ast/path.cpp b/src/ast/path.cpp index 1e2760ef..83cc98dc 100644 --- a/src/ast/path.cpp +++ b/src/ast/path.cpp @@ -321,14 +321,14 @@ void Path::bind_enum_var(const Enum& ent, const ::std::string& name, const ::std } void Path::bind_struct(const Struct& ent, const ::std::vector& args) { - if( args.size() > 0 ) - { - if( args.size() != ent.params().n_params() ) - throw ParseError::Generic("Parameter count mismatch"); - // TODO: Is it the role of this section of code to ensure that the passed args are valid? - // - Probably not, it should instead be the type checker that does it - // - Count validation is OK here though - } + //if( args.size() > 0 ) + //{ + // if( args.size() != ent.params().n_params() ) + // throw ParseError::Generic("Parameter count mismatch"); + // // TODO: Is it the role of this section of code to ensure that the passed args are valid? + // // - Probably not, it should instead be the type checker that does it + // // - Count validation is OK here though + //} DEBUG("Bound to struct"); m_binding_type = STRUCT; diff --git a/src/convert/resolve.cpp b/src/convert/resolve.cpp index 3a1f0fb7..be2bd1bb 100644 --- a/src/convert/resolve.cpp +++ b/src/convert/resolve.cpp @@ -128,6 +128,19 @@ public: m_res.m_module_stack.pop_back(); } + void visit(AST::ExprNode_IfLet& node) + { + DEBUG("ExprNode_IfLet"); + AST::NodeVisitor::visit(node.m_value); + + m_res.start_scope(); + m_res.handle_pattern(node.m_pattern, TypeRef()); + AST::NodeVisitor::visit(node.m_true); + m_res.end_scope(); + + AST::NodeVisitor::visit(node.m_false); + } + void visit(AST::ExprNode_Match& node) { DEBUG("ExprNode_Match"); @@ -351,6 +364,7 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode) // - Invalid afaik, instead Trait::method() is used } + // Search backwards up the stack of anon modules if( m_module_stack.size() ) { AST::Path local_path = m_module_path; @@ -366,6 +380,7 @@ void CPathResolver::handle_path(AST::Path& path, CASTIterator::PathMode mode) local_path.nodes().pop_back(); } } + // Search current module, if found return with no error if( lookup_path_in_module(m_crate, *m_module, m_module_path, path) ) { return; -- cgit v1.2.3