Skip to content

Commit c4aa9ac

Browse files
committed
Fix tests: more friendly error messages for functions
1 parent 9adad25 commit c4aa9ac

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checking.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,19 @@ object Checking {
155155
pot match {
156156
case pot @ ThisRef(cls) =>
157157
assert(cls == state.thisClass, "unexpected potential " + pot.show)
158-
PromoteThis(pot, eff.source, state.path).toErrors
158+
PromoteThis(pot, eff.source, state2.path).toErrors
159159

160160
case _: Cold =>
161-
PromoteCold(eff.source, state.path).toErrors
161+
PromoteCold(eff.source, state2.path).toErrors
162162

163163
case pot @ Warm(cls, outer) =>
164-
PromoteWarm(pot, eff.source, state.path).toErrors
164+
PromoteWarm(pot, eff.source, state2.path).toErrors
165165

166166
case Fun(pots, effs) =>
167167
val errs1 = effs.flatMap { check(_) }
168168
val errs2 = pots.flatMap { pot => check(Promote(pot)(eff.source))(state.copy(path = Vector.empty)) }
169169
if (errs1.nonEmpty || errs2.nonEmpty)
170-
UnsafePromotion(pot, eff.source, state.path, errs1 ++ errs2).toErrors
170+
UnsafePromotion(pot, eff.source, state2.path, errs1 ++ errs2).toErrors
171171
else
172172
Errors.empty
173173

@@ -184,15 +184,15 @@ object Checking {
184184

185185
val target = resolve(cls, field)
186186
if (target.is(Flags.Lazy)) check(MethodCall(pot, target)(eff.source))
187-
else if (!state.fieldsInited.contains(target)) AccessNonInit(target, state.path).toErrors
187+
else if (!state.fieldsInited.contains(target)) AccessNonInit(target, state2.path).toErrors
188188
else Errors.empty
189189

190190
case SuperRef(ThisRef(cls), supercls) =>
191191
assert(cls == state.thisClass, "unexpected potential " + pot.show)
192192

193193
val target = resolveSuper(cls, supercls, field)
194194
if (target.is(Flags.Lazy)) check(MethodCall(pot, target)(eff.source))
195-
else if (!state.fieldsInited.contains(target)) AccessNonInit(target, state.path).toErrors
195+
else if (!state.fieldsInited.contains(target)) AccessNonInit(target, state2.path).toErrors
196196
else Errors.empty
197197

198198
case Warm(cls, outer) =>
@@ -202,7 +202,7 @@ object Checking {
202202
else Errors.empty
203203

204204
case _: Cold =>
205-
AccessCold(field, eff.source, state.path).toErrors
205+
AccessCold(field, eff.source, state2.path).toErrors
206206

207207
case Fun(pots, effs) =>
208208
throw new Exception("Unexpected effect " + eff.show)
@@ -224,7 +224,7 @@ object Checking {
224224
val effs = thisRef.effectsOf(target)
225225
effs.flatMap { check(_) }
226226
}
227-
else CallUnknown(target, eff.source, state.path).toErrors
227+
else CallUnknown(target, eff.source, state2.path).toErrors
228228

229229
case SuperRef(thisRef @ ThisRef(cls), supercls) =>
230230
assert(cls == state.thisClass, "unexpected potential " + pot.show)
@@ -236,7 +236,7 @@ object Checking {
236236
val effs = thisRef.effectsOf(target)
237237
effs.flatMap { check(_) }
238238
}
239-
else CallUnknown(target, eff.source, state.path).toErrors
239+
else CallUnknown(target, eff.source, state2.path).toErrors
240240

241241
case warm @ Warm(cls, outer) =>
242242
val target = resolve(cls, sym)
@@ -245,11 +245,11 @@ object Checking {
245245
val effs = warm.effectsOf(target)
246246
effs.flatMap { check(_) }
247247
}
248-
else if (!sym.isConstructor) CallUnknown(target, eff.source, state.path).toErrors
248+
else if (!sym.isConstructor) CallUnknown(target, eff.source, state2.path).toErrors
249249
else Errors.empty
250250

251251
case _: Cold =>
252-
CallCold(sym, eff.source, state.path).toErrors
252+
CallCold(sym, eff.source, state2.path).toErrors
253253

254254
case Fun(pots, effs) =>
255255
// TODO: assertion might be false, due to SAM

compiler/src/dotty/tools/dotc/transform/init/Errors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ object Errors {
7373
/** Promote `this` under initialization to fully-initialized */
7474
case class PromoteWarm(pot: Warm, source: Tree, trace: Vector[Tree]) extends Error {
7575
def show(implicit ctx: Context): String =
76-
"Promoting the value under initialization to be initialized: " + source.show + "."
76+
"Promoting the value under initialization to be initialized."
7777
}
7878

7979
/** Promote a cold value under initialization to fully-initialized */
@@ -105,7 +105,7 @@ object Errors {
105105

106106
def show(implicit ctx: Context): String = {
107107
var index = 0
108-
"Promoting the value " + source.show + " to initialized is unsafe.\n" + stacktrace +
108+
"Promoting the value to initialized is unsafe.\n" + stacktrace +
109109
"\nThe unsafe promotion may cause the following problem(s):\n" +
110110
(errors.flatMap(_.flatten).map { error =>
111111
index += 1

tests/init/crash/final-fields.scala renamed to tests/init/neg/final-fields.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ object Test1 extends U {
2929
}
3030

3131
object Test extends T {
32-
override final val f1 = /*super.f1*/ 1 + f2
33-
override final val f2 = 2
32+
override final val f1 = /*super.f1*/ 1 + f2 // error
33+
override final val f2 = 2 // error
3434
override final val f3 = {println(3); 3} // error
3535
override val f4 = f3 + 1 // error
3636

tests/init/neg/function10.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Base { self =>
2-
(0 to 10).foreach { i =>
2+
(0 to 10).foreach { i => // error
33
println(a)
44
}
55

6-
val a = 10 // error
6+
val a = 10
77
}

tests/init/neg/function11.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
final class Capture {
22
private[this] var m: Boolean = false
33

4-
(0 to 10).foreach { i =>
4+
(0 to 10).foreach { i => // error
55
f()
66
}
77

8-
val a = 10 // error
8+
val a = 10
99

1010
def f() = while ({
1111
println(a)

tests/init/neg/override15.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
abstract class A {
22
val g = (n: Int) => n + y
3-
val x: Int = f(g)
4-
val y: Int = 10 // error
3+
val x: Int = f(g) // error
4+
val y: Int = 10
55

66
def f(m: Int => Int): Int
77
}

tests/init/neg/override38.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
abstract class A {
22
def f: Int
33

4-
(1 to 10).foreach { i =>
4+
(1 to 10).foreach { i => // error
55
f
66
}
77

88
private val a = 10
99
}
1010

1111
class B extends A {
12-
private val a = 30 // error
12+
private val a = 30
1313
def f: Int = a
1414
}

0 commit comments

Comments
 (0)