File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
main/kotlin/tools/samt/parser
test/kotlin/tools/samt/parser Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -493,11 +493,21 @@ 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 {
499509 message(" Expected an expression" )
500- highlight(locationFromStart(start) , highlightBeginningOnly = true )
510+ highlight(current !! .location , highlightBeginningOnly = true )
501511 }
502512 }
503513 }
Original file line number Diff line number Diff line change @@ -542,6 +542,17 @@ class ParserTest {
542542 val exception = parseWithFatalError(source)
543543 assertEquals(" Expected an expression" , exception.message)
544544 }
545+
546+ @Test
547+ fun `unexpected question mark` () {
548+ val source = """
549+ package a
550+
551+ typealias A = ?String
552+ """
553+ val (_, diagnostics) = parseWithRecoverableError(source)
554+ assertEquals(" Nullability is indicated after a type" , diagnostics.messages.single().message)
555+ }
545556 }
546557
547558 @Nested
You can’t perform that action at this time.
0 commit comments