Skip to content

Commit 24eecb7

Browse files
Fixes on solcore parser. Makes return type defaults to unit, when no type provided. Added a new test case.
Signed-off-by: Rodrigo Ribeiro <[email protected]>
1 parent 9f0fa18 commit 24eecb7

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/Solcore/Frontend/Parser/SolcoreParser.y

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Signature :: { Signature }
224224
Signature : SigPrefix 'function' Name '(' ParamList ')' OptRetTy {Signature (fst $1) (snd $1) $3 $5 $7}
225225

226226
AnnSignature :: { Signature }
227-
AnnSignature : SigPrefix 'function' Name '(' AnnParamList ')' RetTy {Signature (fst $1) (snd $1) $3 $5 $7}
227+
AnnSignature : SigPrefix 'function' Name '(' AnnParamList ')' OptRetTy {Signature (fst $1) (snd $1) $3 $5 (maybe unitTy Just $7)}
228228

229229
SigPrefix :: {([Ty], [Pred])}
230230
SigPrefix : 'forall' Tyvars '.' ConstraintList '=>' {($2, $4)}
@@ -290,9 +290,6 @@ OptRetTy :: { Maybe Ty }
290290
OptRetTy : '->' Type {Just $2}
291291
| {- empty -} {Nothing}
292292

293-
RetTy :: { Maybe Ty }
294-
RetTy : '->' Type {Just $2}
295-
296293
-- Contract constructor
297294

298295
Constructor :: { Constructor }
@@ -585,6 +582,9 @@ tupleExp (t1 : ts) = pairExp t1 (tupleExp ts)
585582
rmquotes :: String -> String
586583
rmquotes = read
587584
585+
unitTy :: Maybe Ty
586+
unitTy = Just (TyCon (Name "()") [])
587+
588588
parseError (Token (line, col) lexeme)
589589
= alexError $ "Parse error while processing lexeme: " ++ show lexeme
590590
++ "\n at line " ++ show line ++ ", column " ++ show col

test/Cases.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ cases =
232232
, runTestExpectingFailure "xref.solc" caseFolder
233233
, runTestForFile "yul-function-typing.solc" caseFolder
234234
, runTestForFile "yul-return.solc" caseFolder
235+
, runTestForFile "optional-return-function-contract.solc" caseFolder
235236
]
236237
where
237238
caseFolder = "./test/examples/cases"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
contract Foo {
2+
3+
function foo (x : word) {
4+
5+
}
6+
}

0 commit comments

Comments
 (0)