@@ -841,21 +841,42 @@ fn (mut p Parser) top_level_stmt() flat.NodeId {
841841// here so the declaration itself is parsed next. When the attribute group is a
842842// disabled `@[if flag ?]` (skip_next_decl set), functions are emitted as no-op
843843// stubs (empty body): the signature must remain so call sites still type-check
844- // and link, but the body is elided. Non-function declarations are emitted as-is .
844+ // and link, but the body is elided. Other disabled declarations are skipped .
845845fn (mut p Parser) parse_decl_after_attrs () flat.NodeId {
846- for p.tok == .semicolon {
847- p.next ()
848- }
846+ p.consume_decl_prefix_after_attrs ()
849847 if p.skip_next_decl {
850848 p.skip_next_decl = false
851- p.disable_fn_body = true
852- res := p.top_level_stmt ()
853- p.disable_fn_body = false
854- return res
849+ if p.cur_decl_is_fn () {
850+ p.disable_fn_body = true
851+ res := p.top_level_stmt ()
852+ p.disable_fn_body = false
853+ p.skip_next_decl = false
854+ return res
855+ }
856+ p.skip_top_level_stmt ()
857+ p.skip_next_decl = false
858+ return flat.empty_node
855859 }
856860 return p.top_level_stmt ()
857861}
858862
863+ fn (mut p Parser) consume_decl_prefix_after_attrs () {
864+ for p.tok == .semicolon || p.tok == .attribute || p.tok == .lsbr {
865+ if p.tok == .semicolon {
866+ p.next ()
867+ continue
868+ }
869+ p.skip_attrs ()
870+ }
871+ }
872+
873+ fn (mut p Parser) cur_decl_is_fn () bool {
874+ if p.tok == .key_fn {
875+ return true
876+ }
877+ return p.tok == .key_pub && p.peek () == .key_fn
878+ }
879+
859880fn (mut p Parser) fn_decl () flat.NodeId {
860881 p.check (.key_fn)
861882 mut name := ''
0 commit comments