@@ -43,7 +43,7 @@ class ExtractUsedNamesSpecification {
4343 |}""" .stripMargin
4444 val compilerForTesting = new ScalaCompilerForUnitTesting
4545 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" )
4747 assertEquals(usedNames(" b.X" ), expectedNames)
4848 }
4949
@@ -58,7 +58,7 @@ class ExtractUsedNamesSpecification {
5858 |}""" .stripMargin
5959 val compilerForTesting = new ScalaCompilerForUnitTesting
6060 val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
61- val expectedNames = standardNames ++ Set (" A" , " a" , " B " , " =" , " Int" )
61+ val expectedNames = standardNames ++ Set (" A" , " a" , " =" , " Int" )
6262 assertEquals(usedNames(" B" ), expectedNames)
6363 }
6464
@@ -78,15 +78,11 @@ class ExtractUsedNamesSpecification {
7878 val compilerForTesting = new ScalaCompilerForUnitTesting
7979 val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB, srcC, srcD)
8080 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" )
9086 assertEquals(usedNames(" A" ), namesA)
9187 assertEquals(usedNames(" A.X" ), namesAX)
9288 assertEquals(usedNames(" B" ), namesB)
@@ -134,23 +130,18 @@ class ExtractUsedNamesSpecification {
134130 |""" .stripMargin
135131 val compilerForTesting = new ScalaCompilerForUnitTesting
136132 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" ,
143137 " foo" ,
144138 " M" ,
145139 " N" ,
146140 " Predef" ,
147141 " ???" ,
148142 " Nothing" )
149- val expectedNames_bar = standardNames ++ Set (" Test_bar" ,
150- " x" ,
151- " B" ,
143+ val expectedNames_bar = standardNames ++ Set (" B" ,
152144 " bar" ,
153- " Param" ,
154145 " P1" ,
155146 " P0" ,
156147 " Predef" ,
@@ -163,37 +154,20 @@ class ExtractUsedNamesSpecification {
163154 assertEquals(usedNames(" Test_bar" ), expectedNames_bar)
164155 }
165156
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-
189157 @ Test
190158 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
194168 val compilerForTesting = new ScalaCompilerForUnitTesting
195169 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" )
197171 assertEquals(usedNames(" Bar" ), expectedNames)
198172 }
199173
@@ -219,7 +193,7 @@ class ExtractUsedNamesSpecification {
219193
220194 // test for https://github.com/gkossakowski/sbt/issues/4
221195 // 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. " )
223197 def extractNamesFromMethodCallOnDynamic = {
224198 val srcA = """ |import scala.language.dynamics
225199 |class A extends Dynamic {
@@ -228,7 +202,7 @@ class ExtractUsedNamesSpecification {
228202 val srcB = " class B { def foo(a: A): Int = a.bla }"
229203 val compilerForTesting = new ScalaCompilerForUnitTesting
230204 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" )
232206 assertEquals(usedNames(" B" ), expectedNames)
233207 }
234208
@@ -306,11 +280,11 @@ class ExtractUsedNamesSpecification {
306280 * definition.
307281 */
308282 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
312284 " 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"
314289 )
315-
316- }
290+ }
0 commit comments