Skip to content

Commit a60b375

Browse files
committed
fix(parser): make question mark before type into recoverable error
1 parent 21eb21d commit a60b375

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

parser/src/main/kotlin/tools/samt/parser/Parser.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,16 @@ class Parser private constructor(
493493
check<OpenBraceToken>() -> parseObjectNode()
494494

495495
skip<AsteriskToken>() -> WildcardNode(locationFromStart(start))
496+
skip<QuestionMarkToken>() -> {
497+
val literal = parseLiteral()
498+
diagnostic.error {
499+
message("Nullability is indicated after a type")
500+
highlight(locationFromStart(start), highlightBeginningOnly = true)
501+
info("A valid nullable type looks like 'Int?' or 'String(size(1..*))?'")
502+
help("To declare the type nullable move the question mark to the end of the type")
503+
}
504+
literal
505+
}
496506

497507
else -> {
498508
diagnostic.fatal {

parser/src/test/kotlin/tools/samt/parser/ParserTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ class ParserTest {
550550
551551
typealias A = ?String
552552
"""
553-
val exception = parseWithFatalError(source)
554-
assertEquals("Expected an expression", exception.message)
553+
val (_, diagnostics) = parseWithRecoverableError(source)
554+
assertEquals("Nullability is indicated after a type", diagnostics.messages.single().message)
555555
}
556556
}
557557

0 commit comments

Comments
 (0)