mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-28 17:32:27 +00:00
Better error messages for variable definitions in macros (#77)
This commit is contained in:
parent
145f2ed711
commit
cba145d674
@ -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,
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user