Consider unqualified function calls.

This commit is contained in:
Frederik Hanghøj Iversen 2019-10-20 22:14:50 +02:00
parent cb26e1727b
commit f84f91327c
2 changed files with 17 additions and 3 deletions

View File

@ -13,7 +13,6 @@ module Rubyhs.References
) where
import Frelude
-- import Data.Language.Ruby hiding (context)
import qualified Data.Language.Ruby as Ruby
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
@ -160,14 +159,29 @@ instance MyMonad (State Env) where
application n = do
Context c <- getContext
let
n' = case n of
-- TODO: Maybe check if there is `a` is a function in the
-- current closure.
(NodeDef (FQN [] a)) -> NodeDef $ FQN (nodeNs c) a
-- Look for the closest enclosing scope that has a reference
-- to `c`. For now we'll just guess that it is a fully
-- qualified reference.
NodeDef{} -> n
-- Ditto as above.
NodeModule{} -> n
go env@Env{applications}
= env { applications = HashMap.insertWith mappend c (Set.singleton n) applications }
= env { applications = HashMap.insertWith mappend c (Set.singleton n') applications }
modify go
getContext = gets Rubyhs.References.context
writeContext q = modify go
where
go env = env { Rubyhs.References.context = q }
nodeNs :: Node -> Namespace
nodeNs = \case
(NodeDef (FQN a _)) -> a
NodeModule n -> n
locally :: MyMonad m => m a -> m a
locally act = do
old <- getContext

View File

@ -32,7 +32,7 @@ tests = go <$> ["mod", "simple"]
let (Ruby.Result refs) = Ruby.references begin
when (refs /= json)
$ assertFailure
$ "Expected " <> convertString (Aeson.encode refs) <> " but got " <> convertString (Aeson.encode json)
$ "Expected " <> convertString (Aeson.encode json) <> " but got " <> convertString (Aeson.encode refs)
decodeFile :: FromJSON a => FilePath -> IO a
decodeFile p = Aeson.eitherDecodeFileStrict' p >>= \case