feat: show exact statement which must be returning at the end of a function
This commit is contained in:
parent
a71045867a
commit
cb9796fa87
@ -105,10 +105,16 @@ object ast {
|
||||
x3: => Parsley[List[Param]],
|
||||
x4: => Parsley[NonEmptyList[Stmt]]
|
||||
): Parsley[FuncDecl] =
|
||||
super.apply(x1, x2, x3, x4).guardAgainst {
|
||||
case FuncDecl(_, _, _, body) if !body.isReturning =>
|
||||
Seq("Function must return on all paths")
|
||||
super.apply(
|
||||
x1,
|
||||
x2,
|
||||
x3,
|
||||
x4.guardAgainst {
|
||||
case body if !body.isReturning =>
|
||||
println(body)
|
||||
Seq("All functions must end in a returning statement")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
case class Param(paramType: Type, name: Ident)
|
||||
|
@ -75,15 +75,15 @@ object parser {
|
||||
|
||||
// Statements
|
||||
private lazy val `<program>` = Program(
|
||||
"begin" ~> many(atomic(`<func>`)),
|
||||
"begin" ~> many(`<func>`),
|
||||
`<stmt>` <~ "end"
|
||||
)
|
||||
private lazy val `<func>` = FuncDecl(
|
||||
`<type>`,
|
||||
`<ident>` <~ "(",
|
||||
atomic(`<type>`),
|
||||
atomic(`<ident>`) <~ "(",
|
||||
sepBy(`<param>`, ",") <~ ")" <~ "is",
|
||||
`<stmt>` <~ "end"
|
||||
)
|
||||
`<stmt>`
|
||||
) <~ "end"
|
||||
private lazy val `<param>` = Param(`<type>`, `<ident>`)
|
||||
private lazy val `<stmt>`: Parsley[NonEmptyList[Stmt]] =
|
||||
sepBy1(`<basic-stmt>`, ";")
|
||||
|
Loading…
x
Reference in New Issue
Block a user