Skip to content

Commit 32e595e

Browse files
committed
Add support for negative numeric literal types
1 parent 3ef991d commit 32e595e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,11 @@ object Parsers {
10371037
else if (in.token == LBRACE)
10381038
atSpan(in.offset) { RefinedTypeTree(EmptyTree, refinement()) }
10391039
else if (isSimpleLiteral) { SingletonTypeTree(literal()) }
1040+
else if (isIdent(nme.raw.MINUS) && in.lookaheadIn(numericLitTokens)) {
1041+
val start = in.offset
1042+
in.nextToken()
1043+
SingletonTypeTree(literal(negOffset = start))
1044+
}
10401045
else if (in.token == USCORE) {
10411046
val start = in.skipToken()
10421047
typeBounds().withSpan(Span(start, in.lastOffset, start))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
type ~~[A, B]
3+
type nonNeg = 2 ~~ 2
4+
5+
type neg0 = -2
6+
type neg1 = -2 ~~ 2
7+
type neg2 = 2 ~~ -2
8+
type neg3 = -2 ~~ -2
9+
}

0 commit comments

Comments
 (0)