Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion parser/src/main/kotlin/tools/samt/parser/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,21 @@ class Parser private constructor(
check<OpenBraceToken>() -> parseObjectNode()

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

else -> {
diagnostic.fatal {
message("Expected an expression")
highlight(locationFromStart(start), highlightBeginningOnly = true)
highlight(current!!.location, highlightBeginningOnly = true)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions parser/src/test/kotlin/tools/samt/parser/ParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,17 @@ class ParserTest {
val exception = parseWithFatalError(source)
assertEquals("Expected an expression", exception.message)
}

@Test
fun `unexpected question mark`() {
val source = """
package a

typealias A = ?String
"""
val (_, diagnostics) = parseWithRecoverableError(source)
assertEquals("Nullability is indicated after a type", diagnostics.messages.single().message)
}
}

@Nested
Expand Down