Skip to content

Commit 0e66a88

Browse files
authored
Merge pull request #6511 from milessabin/topic/negated-numeric-literal-types
Add support for negative numeric literal types
2 parents 72574cf + 32e595e commit 0e66a88

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

+5
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))
+9
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)