diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index ab5484380d37..9d16d4077816 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1037,6 +1037,11 @@ object Parsers { else if (in.token == LBRACE) atSpan(in.offset) { RefinedTypeTree(EmptyTree, refinement()) } else if (isSimpleLiteral) { SingletonTypeTree(literal()) } + else if (isIdent(nme.raw.MINUS) && in.lookaheadIn(numericLitTokens)) { + val start = in.offset + in.nextToken() + SingletonTypeTree(literal(negOffset = start)) + } else if (in.token == USCORE) { val start = in.skipToken() typeBounds().withSpan(Span(start, in.lastOffset, start)) diff --git a/tests/pos/sip23-negative-literals.scala b/tests/pos/sip23-negative-literals.scala new file mode 100644 index 000000000000..26ce7a783e23 --- /dev/null +++ b/tests/pos/sip23-negative-literals.scala @@ -0,0 +1,9 @@ +object Test { + type ~~[A, B] + type nonNeg = 2 ~~ 2 + + type neg0 = -2 + type neg1 = -2 ~~ 2 + type neg2 = 2 ~~ -2 + type neg3 = -2 ~~ -2 +}