Skip to content

Commit

Permalink
repro for #881
Browse files Browse the repository at this point in the history
(cherry picked from commit 99518cb)
  • Loading branch information
yigit authored and KSP Auto Pick committed Apr 4, 2022
1 parent fcdb188 commit ad0ed56
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
13 changes: 13 additions & 0 deletions compiler-plugin/testData/api/typeAlias.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
// A = String
// B = String
// C = A = String
// Int
// List<Int>
// ListOfInt = List<Int>
// ListOfInt = List<Int>
// ListOfInt_B = ListOfInt = List<Int>
// ListOfInt_B = ListOfInt = List<Int>
// ListOfInt_C = ListOfInt_B = ListOfInt = List<Int>
// String
// String
// String
Expand All @@ -30,7 +37,13 @@
typealias A = String
typealias B = String
typealias C = A
typealias ListOfInt = List<Int>
typealias ListOfInt_B = ListOfInt
typealias ListOfInt_C = ListOfInt_B
val a: A = ""
val b: B = ""
val c: C = ""
val d: String = ""
val listOfInt: ListOfInt = TODO()
val listOfInt_B: ListOfInt_B = TODO()
val listOfInt_C: ListOfInt_C = TODO()
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,47 @@ open class TypeAliasProcessor : AbstractTestProcessor() {
}

val sortedTypes = types.sortedBy { it.declaration.simpleName.asString() }

val byFinalSignature = mutableMapOf<String, MutableList<KSType>>()
for (i in sortedTypes) {
val r = mutableListOf<String>()
var a: KSType? = i
do {
r.add(a!!.declaration.simpleName.asString())
while(a != null) {
r.add(a.toSignature())
a = (a.declaration as? KSTypeAlias)?.type?.resolve()
} while (a != null)
}
results.add(r.joinToString(" = "))
byFinalSignature.getOrPut(r.last()) {
mutableListOf()
}.add(i)
}

for (i in types) {
for (j in types) {
assert(i == j)
byFinalSignature.forEach { (signature, sameTypeAliases) ->
for (i in sameTypeAliases) {
for (j in sameTypeAliases) {
assert(i == j) {
"$i and $j both map to $signature, equals should return true"
}
}
}
assert(sameTypeAliases.map { it.hashCode() }.distinct().size == 1) {
"different hashcodes for members of $signature"
}
}


return emptyList()
}

private fun KSType.toSignature(): String = buildString {
append(declaration.simpleName.asString())
if (arguments.isNotEmpty()) {
append("<")
arguments.map {
it.type?.resolve()?.toSignature() ?: "<error>"
}.forEach(this::append)
append(">")
}
}

override fun toResult(): List<String> {
return results
}
Expand Down

0 comments on commit ad0ed56

Please sign in to comment.