Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Solcore/Frontend/Syntax/ElabTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Text.Pretty.Simple
import Solcore.Frontend.Pretty.SolcorePretty
import Solcore.Frontend.Syntax.Contract hiding (contracts, decls)
import Solcore.Frontend.Syntax.Name
import Solcore.Frontend.Syntax.Stmt
import Solcore.Frontend.Syntax.Stmt hiding (paramName)
import qualified Solcore.Frontend.Syntax.SyntaxTree as S
import Solcore.Frontend.Syntax.Ty

Expand Down Expand Up @@ -375,12 +375,16 @@ instance Elab S.Field where
where
env = mempty

paramName :: S.Param -> Name
paramName (S.Typed n _) = n
paramName (S.Untyped n) = n

instance Elab S.FunDef where
type Res S.FunDef = FunDef Name

elab (S.FunDef sig bd)
= do
let vs = names (S.sigVars sig)
let vs = map paramName (S.sigParams sig)
pushVarsInScope vs
sig' <- elab sig
bd' <- elab bd
Expand Down Expand Up @@ -459,7 +463,8 @@ instance Elab S.Exp where
me' <- elab me
isF <- isField n
isCon <- isDefinedConstr n
if isF then -- TODO: check if not shadowed
isVar <- isDefinedVar n
if isF && not isVar then do
pure $ FieldAccess me' n
else if isCon && isNothing me then pure (Con n [])
else pure $ Var n
Expand Down
2 changes: 1 addition & 1 deletion src/Solcore/Frontend/TypeInference/TcContract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ checkClass icls@(Class bvs ps n vs v sigs)
let p = InCls n (TyVar v) (TyVar <$> vs)
ms' = map sigName sigs
bound <- askBoundVariableCondition n
unless bound (checkBoundVariable ps (v:vs) `wrapError` icls)
unless bound (checkBoundVariable ps (map TyVar (v:vs)) `wrapError` icls)
addClassInfo n (length vs) ms' ps p
mapM_ (checkSignature p) sigs
where
Expand Down
8 changes: 4 additions & 4 deletions src/Solcore/Frontend/TypeInference/TcStmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ checkInstance idef@(Instance d vs ctx n ts t funs)
unless patterson (checkMeasure ctx ipred `wrapError` idef)
-- checking bound variable condition
bound <- askBoundVariableCondition n
unless bound (checkBoundVariable ctx (bv (t : ts)) `wrapError` idef)
unless bound (checkBoundVariable ctx (t : ts) `wrapError` idef)
-- checking instance methods
mapM_ (checkMethod ipred) funs `wrapError` idef
let ninst = anfInstance $ ctx :=> InCls n t ts
Expand All @@ -847,9 +847,9 @@ isTyVar _ = False

-- bound variable check

checkBoundVariable :: [Pred] -> [Tyvar] -> TcM ()
checkBoundVariable ps vs
= unless (all (`elem` vs) (bv ps)) $ do
checkBoundVariable :: [Pred] -> [Ty] -> TcM ()
checkBoundVariable ps ts
= unless (all (`elem` (bv ts)) (bv ps)) $ do
throwError "Bounded variable condition fails!"


Expand Down
8 changes: 4 additions & 4 deletions src/Solcore/Pipeline/SolcorePipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ compile opts = runExceptT $ do
putStrLn "> Pattern wildcard desugaring:"
putStrLn $ pretty noWild

-- Eliminate function type arguments
-- Eliminate function type arguments

let noFun = if noDesugarCalls then noWild else replaceFunParam noWild
liftIO $ when verbose $ do
let noFun = if noDesugarCalls then noWild else replaceFunParam noWild
liftIO $ when verbose $ do
putStrLn "> Eliminating argments with function types"
putStrLn $ pretty noFun
putStrLn $ pretty noFun

-- Type inference
(typed, typeEnv) <- ExceptT $ timeItNamed "Typecheck "
Expand Down
1 change: 1 addition & 0 deletions test/Cases.hs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ cases =
, runTestExpectingFailure "xref.solc" caseFolder
, runTestForFile "yul-function-typing.solc" caseFolder
, runTestForFile "yul-return.solc" caseFolder
, runTestForFile "field-var.solc" caseFolder
]
where
caseFolder = "./test/examples/cases"
Expand Down
272 changes: 0 additions & 272 deletions test/examples/cases/dispatch.solc

This file was deleted.

18 changes: 18 additions & 0 deletions test/examples/cases/field-var.solc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import dispatch;
contract Foo {
start : word;

function g(start:word) -> word {
// let start : word = 0;
return Sub.sub(9, start);
}

function f() -> word {
return start;
}

function h(start:word) -> word {
let start : word = 0;
return Sub.sub(9, start);
}
}
2 changes: 1 addition & 1 deletion test/examples/spec/128minierc20.solc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std;
import dispatch;

function caller() -> address {
let res: word;
Expand Down