diff --git a/src/parser.rs b/src/parser.rs index 6c39bf57..b61653e2 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -271,7 +271,7 @@ impl Expr { fn into_property(self, state: &mut ParseState) -> Self { match self { #[cfg(not(feature = "no_module"))] - Self::Variable(.., ref x) if x.1.is_some() => self, + Self::Variable(.., x) if x.1.is_some() => unreachable!("qualified property"), Self::Variable(.., pos, x) => { let ident = x.2; let getter = state.get_identifier(crate::engine::FN_GET, &ident); @@ -1900,18 +1900,16 @@ fn make_dot_expr( x.rhs = make_dot_expr(state, x.rhs, term || terminate_chaining, rhs, op_pos)?; Ok(Expr::Index(x, false, pos)) } + // lhs.module::id - syntax error + #[cfg(not(feature = "no_module"))] + (.., Expr::Variable(.., x)) if x.1.is_some() => { + Err(PERR::PropertyExpected.into_err(x.1.expect("`Some`").0.position())) + } // lhs.id - (lhs, var_expr @ Expr::Variable(..)) if var_expr.is_variable_access(true) => { + (lhs, var_expr @ Expr::Variable(..)) => { let rhs = var_expr.into_property(state); Ok(Expr::Dot(BinaryExpr { lhs, rhs }.into(), false, op_pos)) } - // lhs.module::id - syntax error - #[cfg(not(feature = "no_module"))] - (.., Expr::Variable(.., x)) => { - Err(PERR::PropertyExpected.into_err(x.1.expect("`Some`").0.position())) - } - #[cfg(feature = "no_module")] - (.., Expr::Variable(..)) => unreachable!("qualified property name"), // lhs.prop (lhs, prop @ Expr::Property(..)) => Ok(Expr::Dot( BinaryExpr { lhs, rhs: prop }.into(), @@ -1919,6 +1917,7 @@ fn make_dot_expr( op_pos, )), // lhs.nnn::func(...) - syntax error + #[cfg(not(feature = "no_module"))] (.., Expr::FnCall(func, ..)) if func.is_qualified() => { Err(PERR::PropertyExpected.into_err(func.namespace.expect("`Some`").position())) } diff --git a/tests/var_scope.rs b/tests/var_scope.rs index d7998379..2f50c457 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -60,6 +60,10 @@ fn test_var_scope() -> Result<(), Box> { "let x = 3; let y = 0; { let x = 42; let y = 999; } let x = 123;", )?; + assert_eq!(scope.len(), 2); + assert_eq!(scope.get_value::("x").unwrap(), 123); + assert_eq!(scope.get_value::("y").unwrap(), 0); + assert_eq!( engine.eval::( " @@ -75,10 +79,6 @@ fn test_var_scope() -> Result<(), Box> { ); } - assert_eq!(scope.len(), 2); - assert_eq!(scope.get_value::("x").unwrap(), 123); - assert_eq!(scope.get_value::("y").unwrap(), 0); - Ok(()) }