No parameter names in types for error messages
This commit is contained in:
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import java.lang.AssertionError
|
||||
|
||||
object Renderers {
|
||||
|
||||
@@ -118,7 +119,7 @@ object Renderers {
|
||||
|
||||
@JvmField val RENDER_CLASS_OR_OBJECT_NAME = Renderer<ClassDescriptor> { it.renderKindWithName() }
|
||||
|
||||
@JvmField val RENDER_TYPE = SmartTypeRenderer(DescriptorRenderer.FQ_NAMES_IN_TYPES)
|
||||
@JvmField val RENDER_TYPE = SmartTypeRenderer(DescriptorRenderer.FQ_NAMES_IN_TYPES.withOptions { parameterNamesInFunctionalTypes = false })
|
||||
|
||||
@JvmField val RENDER_POSITION_VARIANCE = Renderer {
|
||||
variance: Variance ->
|
||||
|
||||
@@ -193,6 +193,7 @@ interface DescriptorRendererOptions {
|
||||
var renderConstructorKeyword: Boolean
|
||||
var renderUnabbreviatedType: Boolean
|
||||
var includeAdditionalModifiers: Boolean
|
||||
var parameterNamesInFunctionalTypes: Boolean
|
||||
}
|
||||
|
||||
object ExcludedTypeAnnotations {
|
||||
|
||||
@@ -310,16 +310,16 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
append("(")
|
||||
val parameterTypes = getValueParameterTypesFromFunctionType(type)
|
||||
val parameterNames = type.getParameterNamesFromFunctionType() ?: parameterTypes.map { SpecialNames.NO_NAME_PROVIDED }
|
||||
assert(parameterNames.size == parameterTypes.size) { "Number of names does not match number of types for $type"}
|
||||
val parameterNames = if (parameterNamesInFunctionalTypes) type.getParameterNamesFromFunctionType() else null
|
||||
assert(parameterNames == null || parameterNames.size == parameterTypes.size) { "Number of names does not match number of types for $type"}
|
||||
|
||||
for (index in parameterTypes.indices) {
|
||||
val typeProjection = parameterTypes[index]
|
||||
val name = parameterNames[index]
|
||||
val name = parameterNames?.get(index)
|
||||
|
||||
if (index > 0) append(", ")
|
||||
|
||||
if (!name.isSpecial) {
|
||||
if (name != null && !name.isSpecial) {
|
||||
append(renderName(name))
|
||||
append(": ")
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.renderer
|
||||
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.lang.IllegalStateException
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.jvm.internal.PropertyReference1Impl
|
||||
import kotlin.properties.Delegates
|
||||
@@ -103,4 +104,6 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||
override var renderUnabbreviatedType: Boolean by property(true)
|
||||
|
||||
override var includeAdditionalModifiers: Boolean by property(true)
|
||||
|
||||
override var parameterNamesInFunctionalTypes: Boolean by property(true)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ object IdeRenderers {
|
||||
descriptors.joinToString("") { "<li>${HTML.render(it, context)}</li>" }
|
||||
}
|
||||
|
||||
@JvmField val HTML_RENDER_TYPE = SmartTypeRenderer(DescriptorRenderer.HTML)
|
||||
@JvmField val HTML_RENDER_TYPE = SmartTypeRenderer(DescriptorRenderer.HTML.withOptions { parameterNamesInFunctionalTypes = false })
|
||||
|
||||
@JvmField val HTML_NONE_APPLICABLE_CALLS = Renderer {
|
||||
calls: Collection<ResolvedCall<*>> ->
|
||||
|
||||
@@ -18,7 +18,7 @@ Type inference failed:
|
||||
<td style="white-space:nowrap;"></td>
|
||||
<td style="white-space:nowrap;"></td>
|
||||
<td style="white-space:nowrap;"><b>(</b></td>
|
||||
<td align="right" style="white-space:nowrap;"><font color=red><b>(x: ???) → ???</b></font></td>
|
||||
<td align="right" style="white-space:nowrap;"><font color=red><b>(???) → ???</b></font></td>
|
||||
<td style="white-space:nowrap;"><b>)</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS_NUMBER: 1
|
||||
// !DIAGNOSTICS: TYPE_MISMATCH
|
||||
// !MESSAGE_TYPE: TEXT
|
||||
|
||||
fun foo(handler: (s: String) -> Unit) {
|
||||
bar(handler)
|
||||
}
|
||||
|
||||
fun bar(a: (n: Int) -> Unit) {}
|
||||
@@ -0,0 +1,2 @@
|
||||
<!-- typeMismatchWithFunctionalType1 -->
|
||||
Type mismatch: inferred type is (String) -> Unit but (Int) -> Unit was expected
|
||||
@@ -9,8 +9,8 @@
|
||||
// ACTION: Rename reference
|
||||
// ERROR: A 'return' expression required in a function with a block body ('{...}')
|
||||
// ERROR: The expression cannot be a selector (occur after a dot)
|
||||
// ERROR: Type inference failed: inline fun <T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean): T?<br>cannot be applied to<br>receiver: Collection<List<String>> arguments: ((group: List<String>) -> () -> Boolean)<br>
|
||||
// ERROR: Type mismatch: inferred type is (group: List<String>) -> () -> Boolean but (List<String>) -> Boolean was expected
|
||||
// ERROR: Type inference failed: inline fun <T> Iterable<T>.firstOrNull(predicate: (T) -> Boolean): T?<br>cannot be applied to<br>receiver: Collection<List<String>> arguments: ((List<String>) -> () -> Boolean)<br>
|
||||
// ERROR: Type mismatch: inferred type is (List<String>) -> () -> Boolean but (List<String>) -> Boolean was expected
|
||||
// ERROR: Unresolved reference: maximumSizeOfGroup
|
||||
|
||||
fun doSomethingStrangeWithCollection(collection: Collection<String>): Collection<String>? {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
// ACTION: Create type alias 'NoSuchType'
|
||||
// ACTION: Remove explicit lambda parameter types (may break code)
|
||||
// ACTION: Create type parameter 'NoSuchType' in function 'foo'
|
||||
// ERROR: Type mismatch: inferred type is (x: [ERROR : NoSuchType]) -> Int but Int was expected
|
||||
// ERROR: Type mismatch: inferred type is ([ERROR : NoSuchType]) -> Int but Int was expected
|
||||
// ERROR: Unresolved reference: NoSuchType
|
||||
|
||||
fun foo(): Int {
|
||||
|
||||
@@ -251,6 +251,12 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeMismatchWithFunctionalType.kt")
|
||||
public void testTypeMismatchWithFunctionalType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/typeMismatchWithFunctionalType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeMismatchWithNothing.kt")
|
||||
public void testTypeMismatchWithNothing() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/typeMismatchWithNothing.kt");
|
||||
|
||||
Reference in New Issue
Block a user