diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 4345eeb86..55b718957 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -373,20 +373,22 @@ static void MacSkipDef (unsigned Style, const FilePos* StartPos) /* Skip a macro definition */ { if (Style == MAC_STYLE_CLASSIC) { - /* Skip tokens until we reach the final .endmacro. Be liberal about - ** .endmacro here since we had errors anyway when this function is - ** called. + /* Skip tokens until we reach the final .endmacro. Implement the same + ** behavior as when parsing the macro regularily: .endmacro needs to + ** be at the start of the line to end the macro definition. */ + int LastWasSep = 0; while (1) { if (CurTok.Tok == TOK_EOF) { ErrorExpect ("Expected '.ENDMACRO'"); PNotification (StartPos, "Macro definition started here"); break; } - if (CurTok.Tok == TOK_ENDMACRO) { + if (CurTok.Tok == TOK_ENDMACRO && LastWasSep) { NextTok (); break; } + LastWasSep = (CurTok.Tok == TOK_SEP); NextTok (); } } else { diff --git a/test/asm/listing/122-errormsg.s b/test/asm/listing/122-errormsg.s index 6cabad9f0..8df3ea0f3 100644 --- a/test/asm/listing/122-errormsg.s +++ b/test/asm/listing/122-errormsg.s @@ -1,3 +1,3 @@ .struct x - .word + .word .endstruct diff --git a/test/asm/listing/130-errormsg.s b/test/asm/listing/130-errormsg.s index 5256198b6..eb85bc0e1 100644 --- a/test/asm/listing/130-errormsg.s +++ b/test/asm/listing/130-errormsg.s @@ -1,2 +1,2 @@ lda | - + diff --git a/test/asm/listing/142-errormsg.s b/test/asm/listing/142-errormsg.s new file mode 100644 index 000000000..9c99304f3 --- /dev/null +++ b/test/asm/listing/142-errormsg.s @@ -0,0 +1,6 @@ +.macro mac + .define endmac .endmacro +.endmacro +.macro mac + .define endmac .endmacro +.endmacro diff --git a/test/asm/listing/ref/142-errormsg.err2 b/test/asm/listing/ref/142-errormsg.err2 new file mode 100644 index 000000000..8d15ac44d --- /dev/null +++ b/test/asm/listing/ref/142-errormsg.err2 @@ -0,0 +1,2 @@ +142-errormsg.s:4: Error: A macro named 'mac' is already defined +142-errormsg.s:1: Note: Previous definition of macro 'mac' was here