Skip to content

Add support for negative numeric literal types #6511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/sip23-negative-literals.scala
Original file line number Diff line number Diff line change
@@ -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
}