Repository: square/kotlinpoet
Issue: ClassName empty name ambiguity

This will pass right now on master

```kotlin
val name1 = ClassName("", "", "Taco")
val name2 = ClassName("", "Taco")
assertThat(name1).isEqualTo(name2)
```

This is because their `toString()` is used for equality, and their `toString()`s are surprisingly the same. Their canonical names are different (`".Taco"` and `"Taco"`, respectively).

Not sure if canonical name should match the toString() behavior, toString() should account for this, or if equality should just compare names in an override instead. Or some combination of these.

Changed files:
kotlinpoet/src/main/java/com/squareup/kotlinpoet/TypeName.kt, kotlinpoet/src/test/java/com/squareup/kotlinpoet/ClassNameTest.kt

diff --git a/kotlinpoet/src/main/java/com/squareup/kotlinpoet/TypeName.kt b/kotlinpoet/src/main/java/com/squareup/kotlinpoet/TypeName.kt
index 0e378686..165c7263 100644
--- a/kotlinpoet/src/main/java/com/squareup/kotlinpoet/TypeName.kt
+++ b/kotlinpoet/src/main/java/com/squareup/kotlinpoet/TypeName.kt
@@ -309,6 +309,9 @@ class ClassName internal constructor(
   constructor(packageName: String, vararg simpleNames: String) :
       this(listOf(packageName, *simpleNames)) {
     require(simpleNames.isNotEmpty()) { "simpleNames must not be empty" }
+    require(simpleNames.none { it.isEmpty() }) {
+      "simpleNames must not contain empty items: ${simpleNames.contentToString()}"
+    }
   }
 
   /**
@@ -318,6 +321,9 @@ class ClassName internal constructor(
   constructor(packageName: String, simpleNames: List<String>) :
       this(mutableListOf(packageName).apply { addAll(simpleNames) }) {
     require(simpleNames.isNotEmpty()) { "simpleNames must not be empty" }
+    require(simpleNames.none { it.isEmpty() }) {
+      "simpleNames must not contain empty items: $simpleNames"
+    }
   }
 
   /** From top to bottom. This will be `["java.util", "Map", "Entry"]` for `Map.Entry`.  */
diff --git a/kotlinpoet/src/test/java/com/squareup/kotlinpoet/ClassNameTest.kt b/kotlinpoet/src/test/java/com/squareup/kotlinpoet/ClassNameTest.kt
index c090759f..1aef2dba 100644
--- a/kotlinpoet/src/test/java/com/squareup/kotlinpoet/ClassNameTest.kt
+++ b/kotlinpoet/src/test/java/com/squareup/kotlinpoet/ClassNameTest.kt
@@ -185,4 +185,24 @@ class ClassNameTest {
       |}
       |""".trimMargin())
   }
+
+  @Test fun emptySimpleNamesForbidden() {
+    assertThrows<IllegalArgumentException> {
+      ClassName(packageName = "", simpleNames = *emptyArray())
+    }.hasMessageThat().isEqualTo("simpleNames must not be empty")
+
+    assertThrows<IllegalArgumentException> {
+      ClassName(packageName = "", simpleNames = *arrayOf("Foo", "Bar", ""))
+    }.hasMessageThat().isEqualTo("simpleNames must not contain empty items: " +
+        "[Foo, Bar, ]")
+
+    assertThrows<IllegalArgumentException> {
+      ClassName(packageName = "", simpleNames = emptyList())
+    }.hasMessageThat().isEqualTo("simpleNames must not be empty")
+
+    assertThrows<IllegalArgumentException> {
+      ClassName(packageName = "", simpleNames = listOf("Foo", "Bar", ""))
+    }.hasMessageThat().isEqualTo("simpleNames must not contain empty items: " +
+        "[Foo, Bar, ]")
+  }
 }