Repository navigation
fix(parser): allow line breaks in type annotations - #21
Merged
zombocoder merged 1 commit intoOct 27, 2026
Merged
Conversation
A type annotation could not continue on the next line. `xs:` followed by `List<Int> = ...` on the next line failed with "Expected type name", and `xs: List` followed by `<Int> = ...` failed with "Expected '=' after type". Line breaks inside the type arguments were already accepted. parseTypeName now skips newlines before the type name, and skips newlines between the type name and '<' only when a '<' follows, so the newline that ends a declaration such as `property x: Int` is kept. Tests: ParserTest.TypeAnnotationLineBreakAfterColon and TypeAnnotationLineBreakBeforeTypeArguments (both fail without the change), and TypeAtEndOfLineEndsDeclaration. Signed-off-by: sashml <sashml@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A type annotation cannot continue on the next line:
Line breaks inside the type arguments (after
<, around,) are already accepted, so long generic types can be wrapped there but not at the start of the type.Fix
In
Parser::parseTypeName:<, but only when a<follows them. The newline that ends a declaration such asproperty x: Intis left alone.Every input that parsed before parses the same way. The change only accepts the two forms above, which used to be syntax errors.
Tests
In
tests/test_parser.cpp:ParserTest.TypeAnnotationLineBreakAfterColonandParserTest.TypeAnnotationLineBreakBeforeTypeArgumentscheck that the declared type isList<Int>. Both fail on currentmain.ParserTest.TypeAtEndOfLineEndsDeclarationchecks that a property type at the end of a line still ends that declaration.There is also a CHANGELOG entry under
[Unreleased],Fixed.Verification
o2l_tests515/515 passing.Parser.cppchange reverted, the two line-break tests fail with the errors shown above.o2l runand exits0.clang-format(repository.clang-format) reports nothing on the changed lines.