Skip to content

Commit 5b9b894

Browse files
committed
Add test
1 parent 3196966 commit 5b9b894

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ object Semantic:
11571157
if !isHotSegment then
11581158
for member <- klass.info.decls do
11591159
if member.isClass then
1160-
val error = PromoteError(msg + " Promotion cancelled as the value contains inner classes.", trace.toVector)
1160+
val error = PromoteError("Promotion cancelled as the value contains inner " + member.show + ".", Vector.empty)
11611161
reporter.report(error)
11621162
else if !member.isType && !member.isConstructor && !member.is(Flags.Deferred) then
11631163
given Trace = Trace.empty
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Error: tests/init/neg/promotion-segment3.scala:9:6 ------------------------------------------------------------------
2+
9 | bar(new B) // error
3+
| ^^^^^
4+
| Cannot prove the method argument is hot. Only hot values are safe to leak.
5+
| Found = Warm[class B] { outer = ThisRef[class A] }. Calling trace:
6+
| -> class A: [ promotion-segment3.scala:2 ]
7+
| ^
8+
| -> bar(new B) // error [ promotion-segment3.scala:9 ]
9+
| ^^^^^
10+
|
11+
| Promoting the value to hot failed due to the following problem:
12+
| Promotion cancelled as the value contains inner class C.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
class A:
3+
class B:
4+
class C:
5+
def foo(): Int = m
6+
7+
def bar(b: B) = new b.C().foo()
8+
9+
bar(new B) // error
10+
11+
val m = 10

0 commit comments

Comments
 (0)