@@ -43,7 +43,7 @@ class ExtractUsedNamesSpecification {
43
43
|}""" .stripMargin
44
44
val compilerForTesting = new ScalaCompilerForUnitTesting
45
45
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
46
- val expectedNames = standardNames ++ Set (" a" , " c" , " A" , " B" , " C" , " D" , " b" , " X " , " BB" )
46
+ val expectedNames = standardNames ++ Set (" a" , " c" , " A" , " B" , " C" , " D" , " b" , " BB" )
47
47
assertEquals(usedNames(" b.X" ), expectedNames)
48
48
}
49
49
@@ -58,7 +58,7 @@ class ExtractUsedNamesSpecification {
58
58
|}""" .stripMargin
59
59
val compilerForTesting = new ScalaCompilerForUnitTesting
60
60
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
61
- val expectedNames = standardNames ++ Set (" A" , " a" , " B " , " =" , " Int" )
61
+ val expectedNames = standardNames ++ Set (" A" , " a" , " =" , " Int" )
62
62
assertEquals(usedNames(" B" ), expectedNames)
63
63
}
64
64
@@ -78,15 +78,11 @@ class ExtractUsedNamesSpecification {
78
78
val compilerForTesting = new ScalaCompilerForUnitTesting
79
79
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB, srcC, srcD)
80
80
val scalaVersion = scala.util.Properties .versionNumberString
81
- // TODO: Find out what's making these types appear in 2.10
82
- // They don't come from type dependency traverser, but from `addSymbol`
83
- val versionDependentNames =
84
- if (scalaVersion.contains(" 2.10" )) Set (" Nothing" , " Any" ) else Set ()
85
- val namesA = standardNames ++ Set (" A" ) ++ versionDependentNames
86
- val namesAX = standardNames ++ Set (" X" , " x" , " T" , " A" )
87
- val namesB = Set (" B" , " A" , " Int" , " A;init;" , " scala" )
88
- val namesC = Set (" B;init;" , " C" , " B" )
89
- val namesD = standardNames ++ Set (" D" , " C" , " X" , " foo" , " Int" , " T" )
81
+ val namesA = standardNames ++ Set (" Nothing" , " Any" )
82
+ val namesAX = standardNames ++ Set (" x" , " T" , " A" , " Nothing" , " Any" )
83
+ val namesB = Set (" A" , " Int" , " A;init;" , " Unit" )
84
+ val namesC = Set (" B;init;" , " B" , " Unit" )
85
+ val namesD = standardNames ++ Set (" C" , " X" , " foo" , " Int" , " T" )
90
86
assertEquals(usedNames(" A" ), namesA)
91
87
assertEquals(usedNames(" A.X" ), namesAX)
92
88
assertEquals(usedNames(" B" ), namesB)
@@ -134,23 +130,18 @@ class ExtractUsedNamesSpecification {
134
130
|""" .stripMargin
135
131
val compilerForTesting = new ScalaCompilerForUnitTesting
136
132
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src1, src2)
137
- val expectedNames_lista = standardNames ++ Set (" Test_lista" , " x" , " B" , " lista" , " List" , " A" )
138
- val expectedNames_at = standardNames ++ Set (" Test_at" , " x" , " B" , " at" , " A" , " T" , " X0" , " X1" )
139
- val expectedNames_as = standardNames ++ Set (" Test_as" , " x" , " B" , " as" , " S" , " Y" )
140
- val expectedNames_foo = standardNames ++ Set (" Test_foo" ,
141
- " x" ,
142
- " B" ,
133
+ val expectedNames_lista = standardNames ++ Set (" B" , " lista" , " List" , " A" )
134
+ val expectedNames_at = standardNames ++ Set (" B" , " at" , " A" , " T" , " X0" , " X1" )
135
+ val expectedNames_as = standardNames ++ Set (" B" , " as" , " S" , " Y" )
136
+ val expectedNames_foo = standardNames ++ Set (" B" ,
143
137
" foo" ,
144
138
" M" ,
145
139
" N" ,
146
140
" Predef" ,
147
141
" ???" ,
148
142
" Nothing" )
149
- val expectedNames_bar = standardNames ++ Set (" Test_bar" ,
150
- " x" ,
151
- " B" ,
143
+ val expectedNames_bar = standardNames ++ Set (" B" ,
152
144
" bar" ,
153
- " Param" ,
154
145
" P1" ,
155
146
" P0" ,
156
147
" Predef" ,
@@ -163,37 +154,20 @@ class ExtractUsedNamesSpecification {
163
154
assertEquals(usedNames(" Test_bar" ), expectedNames_bar)
164
155
}
165
156
166
- @ Test
167
- def extractUsedNamesFromExistential = {
168
- val srcFoo =
169
- """ import scala.language.existentials
170
- |class Foo {
171
- | val foo: T forSome { type T <: Double } = ???
172
- |}
173
- """ .stripMargin
174
- val compilerForTesting = new ScalaCompilerForUnitTesting
175
- val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcFoo)
176
- val expectedNames = standardNames ++ Seq (" Double" ,
177
- " Foo" ,
178
- " T" ,
179
- " foo" ,
180
- " scala" ,
181
- " language" ,
182
- " existentials" ,
183
- " Nothing" ,
184
- " ???" ,
185
- " Predef" )
186
- assertEquals(usedNames(" Foo" ), expectedNames)
187
- }
188
-
189
157
@ Test
190
158
def extractUsedNamesFromRefinement = {
191
- val srcFoo =
192
- " object Outer {\n class Inner { type Xyz }\n\n type TypeInner = Inner { type Xyz = Int }\n }"
193
- val srcBar = " object Bar {\n def bar: Outer.TypeInner = null\n }"
159
+ val srcFoo = """ |object Outer {
160
+ | class Inner { type Xyz }
161
+ | type TypeInner = Inner { type Xyz = Int }
162
+ |}
163
+ |""" .stripMargin
164
+ val srcBar = """ |object Bar {
165
+ | def bar: Outer.TypeInner = null
166
+ |}
167
+ |""" .stripMargin
194
168
val compilerForTesting = new ScalaCompilerForUnitTesting
195
169
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcFoo, srcBar)
196
- val expectedNames = standardNames ++ Set (" Bar " , " Outer" , " TypeInner" , " Inner" , " Xyz " , " Int" )
170
+ val expectedNames = standardNames ++ Set (" Outer" , " TypeInner" , " Inner" , " Int" )
197
171
assertEquals(usedNames(" Bar" ), expectedNames)
198
172
}
199
173
@@ -219,7 +193,7 @@ class ExtractUsedNamesSpecification {
219
193
220
194
// test for https://github.com/gkossakowski/sbt/issues/4
221
195
// TODO: we should fix it by having special treatment of `selectDynamic` and `applyDynamic` calls
222
- @ Test
196
+ @ Ignore ( " Call to Dynamic is desugared in type checker so Select nodes is turned into string literal. " )
223
197
def extractNamesFromMethodCallOnDynamic = {
224
198
val srcA = """ |import scala.language.dynamics
225
199
|class A extends Dynamic {
@@ -228,7 +202,7 @@ class ExtractUsedNamesSpecification {
228
202
val srcB = " class B { def foo(a: A): Int = a.bla }"
229
203
val compilerForTesting = new ScalaCompilerForUnitTesting
230
204
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
231
- val expectedNames = standardNames ++ Set (" B " , " A" , " a" , " Int" , " selectDynamic" , " bla" )
205
+ val expectedNames = standardNames ++ Set (" A" , " a" , " Int" , " selectDynamic" , " bla" )
232
206
assertEquals(usedNames(" B" ), expectedNames)
233
207
}
234
208
@@ -306,11 +280,11 @@ class ExtractUsedNamesSpecification {
306
280
* definition.
307
281
*/
308
282
private val standardNames = Set (
309
- " scala" ,
310
- // The default parent of a class is "AnyRef" which is an alias for "Object"
311
- " AnyRef" ,
283
+ // All classes extend Object
312
284
" Object" ,
313
- " java.lang.Object;init;"
285
+ // All classes have a default constructor called <init>
286
+ " java.lang.Object;init;" ,
287
+ // the return type of the default constructor is Unit
288
+ " Unit"
314
289
)
315
-
316
- }
290
+ }
0 commit comments