Skip to content

Fix #7742 : Ensure the indentWidth is never null #7770

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 4 commits into from
Dec 16, 2019
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: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,10 @@ object Scanners {

case class InBraces(var width: IndentWidth | Null, outer: Region)
extends IndentSignificantRegion {
override def indentWidth = width
// The indent width starts out as `null` when the opening brace is encountered
// It is then adjusted when the next token on a new line is encountered.
override def indentWidth: IndentWidth =
if width == null then IndentWidth.Zero else width
}

/** A class describing an indentation region.
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ class TreeChecker extends Phase with SymTransformer {
testDuplicate(sym, seenClasses, "class")
}

val isDeferredAndPrivate = sym.is(Method) && sym.is(Deferred) && sym.is(Private)
assert(!isDeferredAndPrivate, i"$sym is both Deferred and Private")
val badDeferredAndPrivate =
sym.is(Method) && sym.is(Deferred) && sym.is(Private)
&& !sym.hasAnnotation(defn.NativeAnnot)
&& !sym.is(Erased)
assert(!badDeferredAndPrivate, i"$sym is both Deferred and Private")

checkCompanion(symd)

Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i7742.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object A {
for // error // error
}
2 changes: 2 additions & 0 deletions tests/neg/i7753.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class A { if 0 // error
} // error
9 changes: 9 additions & 0 deletions tests/pos/i7741.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class A1 {
@native private def a: Unit
}
trait A2 {
erased def i(a: Int): Int
}
trait A3 {
erased val a: Int
}