1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-05-31 18:41:30 +00:00

Better error messages for variable definitions in macros (#77)

This commit is contained in:
Karol Stasiak 2020-12-01 03:19:38 +01:00
parent 145f2ed711
commit cba145d674
2 changed files with 25 additions and 0 deletions

View File

@ -716,6 +716,18 @@ abstract class MfParser[T](fileId: String, input: String, currentDirectory: Stri
if (statements.isEmpty && alignment.isDefined) log.error(s"Extern function `$name` cannot have alignment", Some(p))
if (statements.isEmpty && !flags("asm") && params.nonEmpty) log.error(s"Extern non-asm function `$name` cannot have parameters", Some(p))
if (flags("asm")) validateAsmFunctionBody(p, flags, name, statements)
if (flags("macro")) {
statements.flatMap(_.find(_.isInstanceOf[VariableDeclarationStatement])) match {
case Some(s) =>
log.error(s"Macro functions cannot declare variables", s.position)
case None =>
}
statements.flatMap(_.find(_.isInstanceOf[ArrayDeclarationStatement])) match {
case Some(s) =>
log.error(s"Macro functions cannot declare arrays", s.position)
case None =>
}
}
Seq(FunctionDeclarationStatement(name, returnType, params.toList,
bank,
addr,

View File

@ -294,4 +294,17 @@ class MacroSuite extends FunSuite with Matchers with AppendedClues {
| }
|""".stripMargin)
}
test("Should not allow variables in macros") {
ShouldNotParse(
"""
|macro void f() {
| byte b
|}
|
|void main() {
| f()
|}
|""".stripMargin)
}
}