From 8bdf82ac8de23f27564c5c8948a5d2c38110327e Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Sun, 1 Mar 2026 13:38:29 +0100 Subject: [PATCH] Fix separating of diverging procedure types from block statements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid creating a procedure literal from a procedure type and a following block statement, one can insert a semicolon or an empty line between the two: // procedure literals p1 :: proc() {…} p2 :: proc() {…} // procedure type followed by a block statement p3 :: proc() {…} The empty line as a separator did not work if the procedure type had a diverging result: // all of these are procedure literals p4 :: proc() -> ! {…} p5 :: proc() -> ! {…} p6 :: proc() -> ! {…} The least annoying fix I came up with is to insert implicit semicolon after the "not" token. I only needed to make sure that the inserted implicit semicolon is being skipped when the "not" token is a part of unary expression to avoid breaking an oddly-formatted code like: b := get_some_bool() if ! b {…} One small side-effect of this change is that in code like below: Proc_Type :: proc() -> ! // Some comment Some_Other_Type :: enum byte {…} The "// Some comment" is not associated with "Proc_Type" anymore. In Odin's standard library this only happens in one place, in `base/runtime/core.odin`: Assertion_Failure_Proc :: #type proc(prefix, message: string, loc: Source_Code_Location) -> ! // Allocation Stuff Allocator_Mode :: enum byte { Alloc, …, } --- src/parser.cpp | 3 +++ src/tokenizer.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/src/parser.cpp b/src/parser.cpp index e98832034..5ada6d298 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3490,6 +3490,9 @@ gb_internal Ast *parse_unary_expr(AstFile *f, bool lhs) { case Token_Mul: // Used for error handling when people do C-like things { Token token = advance_token(f); + if (token.kind == Token_Not) { + skip_possible_newline(f); + } Ast *expr = parse_unary_expr(f, lhs); return ast_unary_expr(f, token, expr); } diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index ffa53abb5..2ba25b297 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -1114,6 +1114,7 @@ semicolon_check:; /*fallthrough*/ case Token_Increment: case Token_Decrement: + case Token_Not: /*fallthrough*/ t->insert_semicolon = true; break;