Stdlib: TreeSet<T> and Iterable<T>.filterTo

I'm playing with this test I've added to CollectionTest.kt:

  fun testSS() {   // TODO would be nice to avoid the <String>   val foo = data.filterTo(sortedSet<String>()){it.startsWith("f")}   }

I provide the sortedSet function in JavaUtil.kt:

inline fun sortedSet<T>(vararg values: T) : TreeSet<T> = values.to(TreeSet<T>(HashSet<T>((values.size))))   
// inline fun sortedSet<T>(vararg values: T) : TreeSet<T> = values.to(TreeSet<T>((values.size)))  // does not compile, and was my first choice

When I run the tests using “mvn clean test”, I get this error when data.filterTo is invoked in the test:

``

ERROR: /Users/petrovic/Projects/kotlin/libraries/testlib/test/CollectionTest.kt: (101, 24) None of the following functions can be called with the arguments supplied:
fun <T : jet.Any?, C : java.util.Collection<in T>>jet.Iterable<T>.filterTo(val result : C, val predicate : (T) -> jet.Boolean) : C defined in <java_root>.kotlin
fun <T : jet.Any?, C : java.util.Collection<in T>>jet.Array<T>.filterTo(val result : C, val predicate : (T) -> jet.Boolean) : C defined in <java_root>.kotlin
fun <T : jet.Any?, C : java.util.Collection<in T>>java.lang.Iterable<T>.filterTo(val result : C, val predicate : (T) -> jet.Boolean) : C defined in <java_root>.kotlin.util

It seems like the filterTo function should handle a java.util.TreeSet, but it does not.  I’m clearly missing something related to generics.

Do you get the same error in the IDE?

I don't think so, judging by the lack of red in the attached screenshot.



[treeset.png|attachment](upload://5u5FCtFsnF1RNyjLsvunTYID4BN.png) (175 KB)

It must be due to the way I'm working.  

I cleared up the problem on my fork by doing, in my top level directory:

$ git fetch upstream; git merge upstream/master $ for i in update_dependencies build; do ant -f $i.xml; done $ cd libraries $ mvn -PlocalKotlin clean test

This cycle takes about 5.5 minutes on my laptop.  If I am using the manually-downloaded EAP 11.1 IDEA, how often to I need to

$ ant -f update_dependencies.xml   # about 4.5 minutes on my laptop

and

$ ant -f build.xml   # about 30 seconds on my laptop


?

And you don't get compilation errors when compiling from the IDE, right?

If you change stdlib, you need to run build.xml.

You need to update_dependencies only if something does not compile when running build.xml.

I must confess that I don't know how to do that.  

If this were a classic maven-based Java project, I’d right click on the specific test method in question and run that one test.  That should result in compilation beforehand.  The 11.1 EAP plugin doesn’t offer that right-click option.

And when I goto the menu and select Rebuild Project to hopefully provide what you ask for, the whole process completely explodes.  That screenshot is attached, with this in the IDEA console window:

``

Information:Using kotlinHome=/Users/petrovic/Library/Application Support/IntelliJIdea11/Kotlin/kotlinc
Information:Invoking in-process compiler org.jetbrains.jet.cli.KotlinCompiler with arguments [-module, /Users/petrovic/Projects/kotlin/libraries/kdoc/target/classes/script.kts, -output, /Users/petrovic/Projects/kotlin/libraries/kdoc/target/classes, -tags]
Information:Invoking in-process compiler org.jetbrains.jet.cli.KotlinCompiler with arguments [-module, /Users/petrovic/Projects/kotlin/libraries/kdoc/target/test-classes/script.kts, -output, /Users/petrovic/Projects/kotlin/libraries/kdoc/target/test-classes, -tags]
Information:Compilation completed with 163 errors and 22 warnings
Information:163 errors
Information:22 warnings
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KModelCompilerPlugin.kt
  Error:Error:line (36)Unresolved reference: CompilerPlugin
  Error:Error:line (40)Unresolved reference: BindingContext
  Error:Error:line (40)Unresolved reference: JetFile
  Error:Error:line (15)Unresolved reference: intellij
  Error:Error:line (16)Unresolved reference: lang
  Error:Error:line (17)Unresolved reference: lang
  Error:Error:line (18)Unresolved reference: compiler
  Error:Error:line (19)Unresolved reference: lang
  Error:Error:line (20)Unresolved reference: lang
  Error:Error:line (21)Unresolved reference: lexer
  Error:Error:line (22)Unresolved reference: lang
  Error:Error:line (23)Unresolved reference: lang
  Error:Error:line (24)Unresolved reference: lang
  Error:Error:line (25)Unresolved reference: lang
  Error:Error:line (26)Unresolved reference: lang
  Error:Error:line (27)Unresolved reference: lang
  Error:Error:line (28)Unresolved reference: lang
  Error:Error:line (29)Unresolved reference: lang
  Error:Error:line (30)Unresolved reference: lang
  Error:Error:line (31)Unresolved reference: util
  Error:Error:line (32)Unresolved reference: lang
  Error:Error:line (40)open fun processFiles(val context : [ERROR : BindingContext], val sources : List<[ERROR : JetFile]>?) : Unit defined in <module>.org.jetbrains.kotlin.doc.model.KModelCompilerPlugin overrides nothing
  Error:Error:line (43)Type mismatch: inferred type is List<[ERROR : JetFile]>? but List<[ERROR : JetFile]> was expected
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocCompiler.kt
  Error:Error:line (22)Unresolved reference: KotlinCompiler
  Error:Error:line (56)Unresolved reference: CompilerArguments
  Error:Error:line (24)Unresolved reference: CompileEnvironment
  Error:Error:line (24)Unresolved reference: CompilerArguments
  Error:Error:line (47)Unresolved reference: CompilerArguments
  Error:Error:line (3)Unresolved reference: cli
  Error:Error:line (4)Unresolved reference: compiler
  Error:Error:line (5)Unresolved reference: cli
  Error:Error:line (47)open fun createArguments() : [ERROR : CompilerArguments] defined in <module>.org.jetbrains.kotlin.doc.KDocCompiler overrides nothing
  Error:Error:line (51)open fun usage(val target : PrintStream?) : Unit defined in <module>.org.jetbrains.kotlin.doc.KDocCompiler overrides nothing
  Error:Error:line (24)open fun configureEnvironment(val environment : [ERROR : CompileEnvironment], val arguments : [ERROR : CompilerArguments], val errStream : PrintStream?) : Unit defined in <module>.org.jetbrains.kotlin.doc.KDocCompiler overrides nothing
  Error:Error:line (14)Unresolved reference: KotlinCompiler
  Error:Error:line (33)Unresolved reference: configureEnvironment
  Error:Error:line (37)None of the following functions can be called with the arguments supplied:
ctor File(val p0 : String?, val p1 : Int) defined in <java_root>.java.io.File
ctor File(val p0 : String?, val p1 : File?) defined in <java_root>.java.io.File
ctor File(val p0 : String?) defined in <java_root>.java.io.File
ctor File(val p0 : String?, val p1 : String?) defined in <java_root>.java.io.File
ctor File(val p0 : File?, val p1 : String?) defined in <java_root>.java.io.File
ctor File(val p0 : URI?) defined in <java_root>.java.io.File
  Warning:Warning:line (37)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type [ERROR : <ERROR PROPERTY TYPE>]
  Error:Error:line (41)Overload resolution ambiguity:
final fun apply() : KDocConfig defined in <module>.org.jetbrains.kotlin.doc.KDocArguments
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt
  Error:Error:line (139)Unresolved reference: DeclarationDescriptor
  Error:Error:line (158)Unresolved reference: BindingContext
  Error:Error:line (557)Unresolved reference: DeclarationDescriptor
  Error:Error:line (577)Unresolved reference: DeclarationDescriptor
  Error:Error:line (587)Unresolved reference: NamespaceDescriptor
  Error:Error:line (677)Unresolved reference: JetType
  Error:Error:line (700)Unresolved reference: ClassDescriptor
  Error:Error:line (749)Unresolved reference: CallableDescriptor
  Error:Error:line (786)Unresolved reference: PropertyDescriptor
  Error:Error:line (805)Unresolved reference: TypeParameterDescriptor
  Error:Error:line (51)Unresolved reference: DeclarationDescriptor
  Error:Error:line (53)Unresolved reference: DeclarationDescriptor
  Error:Error:line (182)Unresolved reference: JetFile
  Error:Error:line (213)Unresolved reference: NamespaceDescriptor
  Error:Error:line (233)Unresolved reference: DeclarationDescriptor
  Error:Error:line (246)Unresolved reference: JetScope
  Error:Error:line (275)Unresolved reference: CallableDescriptor
  Error:Error:line (301)Unresolved reference: TypeParameterDescriptor
  Error:Error:line (312)Unresolved reference: TypeParameterDescriptor
  Error:Error:line (319)Unresolved reference: ValueParameterDescriptor
  Error:Error:line (331)Unresolved reference: DeclarationDescriptor
  Error:Error:line (378)Unresolved reference: DeclarationDescriptor
  Error:Error:line (383)Unresolved reference: JetType
  Error:Error:line (410)Unresolved reference: ClassDescriptor
  Error:Error:line (597)Unresolved reference: ClassDescriptor
  Error:Error:line (9)Unresolved reference: lang
  Error:Error:line (10)Unresolved reference: lang
  Error:Error:line (11)Unresolved reference: lang
  Error:Error:line (12)Unresolved reference: lang
  Error:Error:line (13)Unresolved reference: lang
  Error:Error:line (14)Unresolved reference: lang
  Error:Error:line (15)Unresolved reference: lang
  Error:Error:line (16)Unresolved reference: lexer
  Error:Error:line (17)Unresolved reference: lang
  Error:Error:line (18)Unresolved reference: lang
  Error:Error:line (19)Unresolved reference: lang
  Error:Error:line (20)Unresolved reference: lang
  Error:Error:line (21)Unresolved reference: lang
  Error:Error:line (22)Unresolved reference: lang
  Error:Error:line (23)Unresolved reference: lang
  Error:Error:line (24)Unresolved reference: lang
  Error:Error:line (34)Unresolved reference: lang
  Error:Error:line (54)Unresolved reference: ModuleDescriptor
  Warning:Warning:line (58)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type [ERROR : <ERROR FUNCTION RETURN TYPE>]
  Error:Error:line (59)None of the following functions can be called with the arguments supplied:
final fun String.startsWith(val prefix : String) : Boolean defined in <java_root>.kotlin
final fun String.startsWith(val prefix : String, val toffset : Int) : Boolean defined in <java_root>.kotlin
  Warning:Warning:line (62)Type was casted to ‘Any’. Please specify ‘Any’ as expected type, if you mean such cast
  Error:Error:line (63)None of the following functions can be called with the arguments supplied:
final fun String.startsWith(val prefix : String) : Boolean defined in <java_root>.kotlin
final fun String.startsWith(val prefix : String, val toffset : Int) : Boolean defined in <java_root>.kotlin
  Error:Error:line (63)None of the following functions can be called with the arguments supplied:
final fun String.substring(val beginIndex : Int) : String defined in <java_root>.kotlin
final fun String.substring(val beginIndex : Int, val endIndex : Int) : String defined in <java_root>.kotlin
  Error:Error:line (63)Type mismatch: inferred type is Any but String was expected
  Error:Error:line (183)Unresolved reference: NamespaceDescriptor
  Error:Error:line (187)Unresolved reference: BindingContextUtils
  Error:Error:line (197)Unresolved reference: ClassDescriptor
  Error:Error:line (202)Unresolved reference: NamespaceDescriptor
  Error:Error:line (234)Unresolved reference: ModuleDescriptor
  Error:Error:line (250)Unresolved reference: PropertyDescriptor
  Error:Error:line (251)Overload resolution ambiguity:
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
  Error:Error:line (252)Overload resolution ambiguity:
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
  Error:Error:line (254)Overload resolution ambiguity:
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
  Error:Error:line (255)Unresolved reference: ExtensionReceiver
  Error:Error:line (256)Overload resolution ambiguity:
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
  Error:Error:line (262)Unresolved reference: CallableDescriptor
  Warning:Warning:line (278)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type [ERROR : <ERROR FUNCTION RETURN TYPE>]
  Error:Error:line (289)Type mismatch: inferred type is Any but String was expected
  Error:Error:line (293)Unresolved reference: ExtensionReceiver
  Error:Error:line (294)Overload resolution ambiguity:
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
  Error:Error:line (333)Unresolved reference: BindingContextUtils
  Error:Error:line (342)Unresolved reference: JetTokens
  Error:Error:line (342)Unresolved reference: JetTokens
  Error:Error:line (346)Unresolved reference: JetTokens
  Warning:Warning:line (347)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type [ERROR : <ERROR FUNCTION RETURN TYPE>]
  Error:Error:line (349)None of the following functions can be called with the arguments supplied:
final fun String.trim(val prefix : String, val postfix : String) : String defined in <java_root>.kotlin
final fun String.trim(val text : String) : String defined in <java_root>.kotlin
final fun String.trim() : String defined in <java_root>.kotlin
  Warning:Warning:line (355)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type [ERROR : <ERROR FUNCTION RETURN TYPE>]
  Warning:Warning:line (355)Name shadowed: text
  Error:Error:line (356)None of the following functions can be called with the arguments supplied:
final fun String.trim(val prefix : String, val postfix : String) : String defined in <java_root>.kotlin
final fun String.trim(val text : String) : String defined in <java_root>.kotlin
final fun String.trim() : String defined in <java_root>.kotlin
  Error:Error:line (358)Type mismatch: inferred type is Any but String was expected
  Error:Error:line (362)compareTo() must return Int, but returns [ERROR : <ERROR FUNCTION RETURN TYPE>]
  Error:Error:line (363)Type mismatch: inferred type is Any but String was expected
  Error:Error:line (364)compareTo() must return Int, but returns [ERROR : <ERROR FUNCTION RETURN TYPE>]
  Error:Error:line (365)Type mismatch: inferred type is Any but String was expected
  Error:Error:line (372)Type mismatch: inferred type is Any but String was expected
  Error:Error:line (386)Unresolved reference: ClassDescriptor
  Warning:Warning:line (401)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type String
  Error:Error:line (402)Overload resolution ambiguity:
final fun getPackage(val name : String) : KPackage? defined in <module>.org.jetbrains.kotlin.doc.model.KModel
final fun getPackage(val descriptor : [ERROR : NamespaceDescriptor]) : KPackage defined in <module>.org.jetbrains.kotlin.doc.model.KModel
  Warning:Warning:line (404)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type String
  Error:Error:line (413)Unresolved reference: NamespaceDescriptor
  Error:Error:line (415)Overload resolution ambiguity:
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
open fun <ERROR FUNCTION>() : [ERROR : <ERROR FUNCTION RETURN TYPE>] defined in <ERROR MODULE>.<ERROR CLASS>
  Error:Error:line (474)Overload resolution ambiguity:
final fun getPackage(val name : String) : KPackage? defined in <module>.org.jetbrains.kotlin.doc.model.KModel
final fun getPackage(val descriptor : [ERROR : NamespaceDescriptor]) : KPackage defined in <module>.org.jetbrains.kotlin.doc.model.KModel
  Error:Error:line (478)Overload resolution ambiguity:
final fun getClass(val classElement : [ERROR : ClassDescriptor]) : KClass? defined in <module>.org.jetbrains.kotlin.doc.model.KModel
final fun getClass(val qualifiedName : String) : KClass? defined in <module>.org.jetbrains.kotlin.doc.model.KModel
  Error:Error:line (486)Overload resolution ambiguity:
final fun getClass(val classElement : [ERROR : ClassDescriptor]) : KClass? defined in <module>.org.jetbrains.kotlin.doc.model.KModel
final fun getClass(val qualifiedName : String) : KClass? defined in <module>.org.jetbrains.kotlin.doc.model.KModel
  Warning:Warning:line (336)The expression is unused
  Warning:Warning:line (422)Parameter ‘pkg’ is never used
  Warning:Warning:line (427)Parameter ‘pkg’ is never used
  Warning:Warning:line (660)Parameter ‘pkg’ is never used
  Warning:Warning:line (665)Parameter ‘pkg’ is never used
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDoc.kt
  Error:Error:line (15)Unresolved reference: intellij
  Error:Error:line (16)Unresolved reference: lang
  Error:Error:line (17)Unresolved reference: lang
  Error:Error:line (18)Unresolved reference: compiler
  Error:Error:line (19)Unresolved reference: lang
  Error:Error:line (20)Unresolved reference: lang
  Error:Error:line (21)Unresolved reference: lexer
  Error:Error:line (22)Unresolved reference: lang
  Error:Error:line (23)Unresolved reference: lang
  Error:Error:line (24)Unresolved reference: lang
  Error:Error:line (25)Unresolved reference: lang
  Error:Error:line (26)Unresolved reference: lang
  Error:Error:line (27)Unresolved reference: lang
  Error:Error:line (28)Unresolved reference: lang
  Error:Error:line (29)Unresolved reference: lang
  Error:Error:line (30)Unresolved reference: lang
  Error:Error:line (31)Unresolved reference: util
  Error:Error:line (32)Unresolved reference: lang
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/JavadocStyleHtmlDoclet.kt
  Error:Error:line (15)Unresolved reference: intellij
  Error:Error:line (16)Unresolved reference: lang
  Error:Error:line (17)Unresolved reference: lang
  Error:Error:line (18)Unresolved reference: compiler
  Error:Error:line (19)Unresolved reference: lang
  Error:Error:line (20)Unresolved reference: lang
  Error:Error:line (21)Unresolved reference: lexer
  Error:Error:line (22)Unresolved reference: lang
  Error:Error:line (23)Unresolved reference: lang
  Error:Error:line (24)Unresolved reference: lang
  Error:Error:line (25)Unresolved reference: lang
  Error:Error:line (26)Unresolved reference: lang
  Error:Error:line (27)Unresolved reference: lang
  Error:Error:line (28)Unresolved reference: lang
  Error:Error:line (29)Unresolved reference: lang
  Error:Error:line (30)Unresolved reference: lang
  Error:Error:line (31)Unresolved reference: util
  Error:Error:line (32)Unresolved reference: lang
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageSummaryTemplate.kt
  Warning:Warning:line (140)Unnecessary safe call on a non-null receiver of type Entry<String, List<KClass>>
  Warning:Warning:line (140)Elvis operator (?:slight_smile: always returns the left operand of non-nullable type String
  Warning:Warning:line (141)Unnecessary safe call on a non-null receiver of type Entry<String, List<KClass>>
  Warning:Warning:line (279)Unnecessary safe call on a non-null receiver of type Entry<KClass, SortedSet<KFunction>>
  Warning:Warning:line (284)Unnecessary safe call on a non-null receiver of type Entry<KClass, SortedSet<KFunction>>
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageFrameTemplate.kt
  Warning:Warning:line (100)Unnecessary safe call on a non-null receiver of type Entry<KClass, List<KFunction>>
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/KDocConfig.kt
  Warning:Warning:line (73)Unnecessary safe call on a non-null receiver of type Entry<String, String>
  Warning:Warning:line (74)Unnecessary safe call on a non-null receiver of type Entry<String, String>
/Users/petrovic/Projects/kotlin/libraries/kdoc/src/test/kotlin/test/kotlin/template/TemplateCoreTest.kt
  Error:Error:line (12)Unresolved reference: TextTemplate
  Error:Error:line (18)Unresolved reference: TextTemplate
  Error:Error:line (13)open fun render() : Unit defined in <module>.test.kotlin.template.EmailTemplate overrides nothing
  Error:Error:line (19)open fun render() : Unit defined in <module>.test.kotlin.template.MoreDryTemplate overrides nothing
  Error:Error:line (20)No value passed for parameter value-parameter val other : Any? defined in jet.String.plus
  Error:Error:line (26)Unresolved reference: renderToText
  Error:Error:line (33)Unresolved reference: renderToText
  Error:Error:line (40)Unresolved reference: renderToText



rebuildfails.png (192 KB)

ae6rt wrote:

I must confess that I don’t know how to do that.  

If this were a classic maven-based Java project, I’d right click on the specific test method in question and run that one test.  That should result in compilation beforehand.  The 11.1 EAP plugin doesn’t offer that right-click option.

So the right click -> Run script/test was working recently. Since I trashed my libraries IDEA project and opened the mvn project it stopped working again for me too :)

Its now working again; I moved the testlib/test directory into stdlib; so its got a src and test directory; then IDEA’s mvn support detects the source and test code correctly.

So pull again

``

git fetch upstream; git merge upstream/master

and you should be able to try this now.

Though one thing to be careful of - I found the stdlib didn’t depend on the KotlinRuntime library - so I had to go into the dependencies and add that one (IDEA knows about KotlinRuntime as a library so I just picked it from the list). Otherwise it complained that jet.JetObject wasn’t found when I run the test case. Once you’ve done that, you should be able to run unit tests directly - e.g. CollectionTest

Things are a little complex when adding new code to the stdlib; I tend to run IDEA from the top level IDEA project; so whenever I change the API of stdlib, I run “ant dist” in the top level, then stop and restart the child IDEA. However when just editing test cases and stuff its fine to work inside IDEA and have the usual edit/run/debug cycle.