1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 21:31:48 +03:00

Call ref on the rhs in order to bind the lhs to the rhs in MemberAccess

Temporarily call `eval rhs >> ref rhs` because we don't set up `Reader Span` correctly when calling `ref`.
This commit is contained in:
joshvera 2018-12-20 19:36:31 -05:00
parent 6ebbc848e9
commit 250eedc742

View File

@ -504,29 +504,24 @@ instance Ord1 MemberAccess where liftCompare = genericLiftCompare
instance Show1 MemberAccess where liftShowsPrec = genericLiftShowsPrec instance Show1 MemberAccess where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable MemberAccess where instance Evaluatable MemberAccess where
eval eval _ MemberAccess{..} = do eval eval ref MemberAccess{..} = do
lhsValue <- eval lhs lhsValue <- eval lhs
lhsFrame <- Abstract.scopedEnvironment lhsValue lhsFrame <- Abstract.scopedEnvironment lhsValue
slot <- case lhsFrame of slot <- case lhsFrame of
Just lhsFrame -> Just lhsFrame ->
withScopeAndFrame lhsFrame $ do -- FIXME: The span is not set up correctly when calling `ref` so we have to eval
span <- ask @Span -- it first
reference (Reference rhs) span ScopeGraph.MemberAccess (Declaration rhs) withScopeAndFrame lhsFrame (eval rhs >> ref rhs)
lookupDeclaration (Declaration rhs)
-- Throw a ReferenceError since we're attempting to reference a name within a value that is not an Object. -- Throw a ReferenceError since we're attempting to reference a name within a value that is not an Object.
Nothing -> throwEvalError (ReferenceError lhsValue rhs) Nothing -> throwEvalError (ReferenceError lhsValue rhs)
value <- deref slot value <- deref slot
bindThis lhsValue value bindThis lhsValue value
ref eval _ MemberAccess{..} = do ref eval ref' MemberAccess{..} = do
lhsValue <- eval lhs lhsValue <- eval lhs
lhsFrame <- Abstract.scopedEnvironment lhsValue lhsFrame <- Abstract.scopedEnvironment lhsValue
case lhsFrame of case lhsFrame of
Just lhsFrame -> Just lhsFrame -> withScopeAndFrame lhsFrame (ref' rhs)
withScopeAndFrame lhsFrame $ do
span <- ask @Span
reference (Reference rhs) span ScopeGraph.MemberAccess (Declaration rhs)
lookupDeclaration (Declaration rhs)
-- Throw a ReferenceError since we're attempting to reference a name within a value that is not an Object. -- Throw a ReferenceError since we're attempting to reference a name within a value that is not an Object.
Nothing -> throwEvalError (ReferenceError lhsValue rhs) Nothing -> throwEvalError (ReferenceError lhsValue rhs)