Skip to content
Closed
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
16 changes: 13 additions & 3 deletions src/Solcore/Frontend/TypeInference/TcStmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,20 @@ verifySignatures instd@(Instance _ _ ps n ts t funs) =

checkMemberType :: (Name, Qual Ty, Qual Ty) -> TcM ()
checkMemberType (qn, qt@(ps :=> t), qt'@(ps' :=> t'))
= do
_ <- tcmMatch t t' `catchError` (\ _ -> invalidMemberType qn t t')
pure ()
-- when we have a closure in the instance type,
-- it will not be an instance of the most general
-- type present in the type class.
| hasClosureType t = pure ()
-- no closure, we can check if the infered type is
-- an instance of the class annotated most general
-- type.
| otherwise
= do
_ <- tcmMatch t t' `catchError` (\ _ -> invalidMemberType qn t t')
pure ()

hasClosureType :: Ty -> Bool
hasClosureType = any isClosureName . tyconNames

invalidMemberType :: Name -> Ty -> Ty -> TcM a
invalidMemberType n cls ins
Expand Down
2 changes: 2 additions & 0 deletions test/Cases.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ cases =
, runTestForFile "yul-function-typing.solc" caseFolder
, runTestForFile "yul-return.solc" caseFolder
, runTestExpectingFailure "unbound-instance-var.solc" caseFolder
, runTestForFile "closure-fun-single.solc" caseFolder
, runTestForFile "instance-closure-error.solc" caseFolder
]
where
caseFolder = "./test/examples/cases"
Expand Down
5 changes: 5 additions & 0 deletions test/examples/cases/closure-fun-single.solc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function ct(x : word) -> ((word) -> word) {
return lam(y : word) {
return x;
};
}
11 changes: 11 additions & 0 deletions test/examples/cases/instance-closure-error.solc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
forall t . class t:CtFun {
function ct(x : t) -> ((t) -> t);
}

instance word:CtFun {
function ct(x : word) -> ((word) -> word) {
return lam(y : word) {
return x;
};
}
}