File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed
compiler/src/dotty/tools/dotc/transform/init Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,10 @@ object Checking {
95
95
&& (obj.enclosingClass == state.thisClass
96
96
|| obj.appearsInside(state.thisClass) && state.superConstrCalled)
97
97
98
+ /** Whether the obj is directly nested inside the current class */
99
+ private def isNestedObject (obj : Global )(using state : State ): Boolean =
100
+ obj.symbol.owner == state.thisClass
101
+
98
102
// ------- checking construtor ---------------------------
99
103
100
104
/** Check that the given concrete class may be initialized safely
@@ -257,6 +261,9 @@ object Checking {
257
261
val target = resolve(obj.moduleClass, sym)
258
262
if isObjectAccessSafe(obj) then
259
263
check(MethodCall (ThisRef ()(obj.source), target)(eff.source))
264
+ else if isNestedObject(obj) then
265
+ val pot = FieldReturn (ThisRef ()(obj.source), obj.symbol)(obj.source)
266
+ check(MethodCall (pot, target)(eff.source))
260
267
else
261
268
state.dependencies += StaticCall (obj.moduleClass, target)(state.path)
262
269
Errors .empty
Original file line number Diff line number Diff line change
1
+ // from Scala.js
2
+ object Names {
3
+ private final val ConstructorSimpleEncodedName : String =
4
+ " <init>"
5
+
6
+ final class SimpleMethodName (encoded : String )
7
+
8
+ object SimpleMethodName {
9
+ def apply (name : String ): SimpleMethodName =
10
+ val res = name == ConstructorSimpleEncodedName
11
+ new SimpleMethodName (name)
12
+ }
13
+
14
+ val ConstructorSimpleName : SimpleMethodName =
15
+ SimpleMethodName (ConstructorSimpleEncodedName )
16
+ }
17
+
18
+ object A { // error
19
+ val n : Int = B .m
20
+ }
21
+
22
+ object B {
23
+ val m : Int = A .n
24
+ }
Original file line number Diff line number Diff line change 2
2
4 | val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error
3
3
| ^^^^^^^^^^^^^^^
4
4
| Promoting the value to fully-initialized is unsafe.
5
- | Calling trace:
5
+ | Calling trace (full) :
6
6
| -> val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error [ t3273.scala:4 ]
7
7
|
8
8
| The unsafe promotion may cause the following problem(s):
9
9
|
10
- | 1. Access non-initialized value num1. Calling trace:
10
+ | 1. Access non-initialized value num1. Calling trace (full) :
11
11
| -> val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error [ t3273.scala:4 ]
12
12
-- Error: tests/init/neg/t3273.scala:5:61 ------------------------------------------------------------------------------
13
13
5 | val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error
14
14
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
15
| Promoting the value to fully-initialized is unsafe.
16
- | Calling trace:
16
+ | Calling trace (full) :
17
17
| -> val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error [ t3273.scala:5 ]
18
18
|
19
19
| The unsafe promotion may cause the following problem(s):
20
20
|
21
- | 1. Access non-initialized value num2. Calling trace:
21
+ | 1. Access non-initialized value num2. Calling trace (full) :
22
22
| -> val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error [ t3273.scala:5 ]
You can’t perform that action at this time.
0 commit comments