Fix blocks getting invalid ranges
This commit is contained in:
parent
20014a7926
commit
508b111374
@ -1,7 +1,7 @@
|
||||
|
||||
function main() : int is
|
||||
block
|
||||
var j := 1;
|
||||
block {
|
||||
var j : int := 1;
|
||||
j := j + 1;
|
||||
j := j - 1;
|
||||
with j
|
||||
j := j - 1
|
||||
} with j
|
@ -12,13 +12,19 @@ import Range
|
||||
import Pretty
|
||||
import Product
|
||||
|
||||
import Data.Text (Text)
|
||||
-- import Debug.Trace
|
||||
|
||||
type CanSearch xs =
|
||||
( Contains [ScopedDecl] xs
|
||||
, Contains Range xs
|
||||
, Contains (Maybe Category) xs
|
||||
, Contains [Text] xs
|
||||
, Pretty (Product xs)
|
||||
)
|
||||
|
||||
findScopedDecl
|
||||
:: ( Contains [ScopedDecl] xs
|
||||
, Contains Range xs
|
||||
, Contains (Maybe Category) xs
|
||||
)
|
||||
:: CanSearch xs
|
||||
=> Range
|
||||
-> Pascal (Product xs)
|
||||
-> Maybe ScopedDecl
|
||||
@ -32,10 +38,7 @@ findScopedDecl pos tree = do
|
||||
lookupEnv (ppToText $ void pt) filtered
|
||||
|
||||
definitionOf
|
||||
:: ( Contains [ScopedDecl] xs
|
||||
, Contains Range xs
|
||||
, Contains (Maybe Category) xs
|
||||
)
|
||||
:: CanSearch xs
|
||||
=> Range
|
||||
-> Pascal (Product xs)
|
||||
-> Maybe Range
|
||||
@ -43,10 +46,7 @@ definitionOf pos tree =
|
||||
_sdOrigin <$> findScopedDecl pos tree
|
||||
|
||||
typeOf
|
||||
:: ( Contains [ScopedDecl] xs
|
||||
, Contains Range xs
|
||||
, Contains (Maybe Category) xs
|
||||
)
|
||||
:: CanSearch xs
|
||||
=> Range
|
||||
-> Pascal (Product xs)
|
||||
-> Maybe (Either (Pascal ()) Kind)
|
||||
@ -54,10 +54,7 @@ typeOf pos tree =
|
||||
_sdType =<< findScopedDecl pos tree
|
||||
|
||||
implementationOf
|
||||
:: ( Contains [ScopedDecl] xs
|
||||
, Contains Range xs
|
||||
, Contains (Maybe Category) xs
|
||||
)
|
||||
:: CanSearch xs
|
||||
=> Range
|
||||
-> Pascal (Product xs)
|
||||
-> Maybe Range
|
||||
@ -65,10 +62,7 @@ implementationOf pos tree =
|
||||
_sdBody =<< findScopedDecl pos tree
|
||||
|
||||
referencesOf
|
||||
:: ( Contains [ScopedDecl] xs
|
||||
, Contains Range xs
|
||||
, Contains (Maybe Category) xs
|
||||
)
|
||||
:: CanSearch xs
|
||||
=> Range
|
||||
-> Pascal (Product xs)
|
||||
-> Maybe [Range]
|
||||
|
@ -15,7 +15,8 @@ import Range
|
||||
import Product
|
||||
import Tree hiding (skip)
|
||||
|
||||
-- import Debug.Trace
|
||||
import Pretty
|
||||
import Debug.Trace
|
||||
|
||||
ranged
|
||||
:: ( Functor f
|
||||
@ -779,11 +780,12 @@ letExpr = do
|
||||
-> Pascal ASTInfo
|
||||
-> Pascal ASTInfo
|
||||
-> Pascal ASTInfo
|
||||
let'' r decl b = mk (Cons r' rest) $ Let decl b
|
||||
let'' r decl b =
|
||||
mk (Cons r' rest) $ Let decl b
|
||||
where
|
||||
r' = Range start end f
|
||||
Range _ end f = r
|
||||
Cons (Range start _ _) rest = infoOf b
|
||||
Cons (Range start _ _) rest = infoOf decl
|
||||
|
||||
statement :: Parser (Pascal ASTInfo)
|
||||
statement = ranged do pure Action <*> expr
|
||||
@ -913,12 +915,12 @@ example :: FilePath
|
||||
-- example = "../../../src/test/contracts/bytes_arithmetic.ligo"
|
||||
-- example = "../../../src/test/contracts/bytes_unpack.ligo"
|
||||
-- example = "../../../src/test/contracts/chain_id.ligo"
|
||||
-- example = "../../../src/test/contracts/coase.ligo"
|
||||
example = "../../../src/test/contracts/coase.ligo"
|
||||
-- example = "../../../src/test/contracts/failwith.ligo"
|
||||
-- example = "../../../src/test/contracts/loop.ligo"
|
||||
-- example = "../../../src/test/contracts/redeclaration.ligo"
|
||||
-- example = "../../../src/test/contracts/includer.ligo"
|
||||
-- example = "../../../src/test/contracts/namespaces.ligo"
|
||||
example = "../../../src/test/contracts/application.ligo"
|
||||
-- example = "../../../src/test/contracts/blocks.ligo"
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
-- example = "../../../src/test/contracts/application.ligo"
|
||||
|
@ -220,6 +220,10 @@ instance Pretty ScopedDecl where
|
||||
instance Pretty Kind where
|
||||
pp _ = "TYPE"
|
||||
|
||||
instance Pretty Category where
|
||||
pp Variable = "Variable"
|
||||
pp Type = "Type"
|
||||
|
||||
-- | Search for a name inside a local scope.
|
||||
lookupEnv :: Text -> [ScopedDecl] -> Maybe ScopedDecl
|
||||
lookupEnv name = listToMaybe . filter ((name ==) . ppToText . _sdName)
|
||||
|
@ -34,7 +34,7 @@ import Pretty
|
||||
import Error
|
||||
import Range
|
||||
|
||||
-- import Debug.Trace
|
||||
import Debug.Trace
|
||||
|
||||
-- | A tree, where each layer is one of @layers@ `Functor`s.
|
||||
--
|
||||
@ -115,6 +115,9 @@ lookupTree
|
||||
. ( Apply Foldable fs
|
||||
, Apply Functor fs
|
||||
, HasRange info
|
||||
-- , HasComments info
|
||||
-- , Pretty1 (Sum fs)
|
||||
-- , Pretty info
|
||||
)
|
||||
=> Range
|
||||
-> Tree fs info
|
||||
|
Loading…
Reference in New Issue
Block a user