diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/ListLiteralType.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/ListLiteralType.kt index 4524b17dbc88..b5435feb0c9a 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/ListLiteralType.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/typing/ListLiteralType.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.lang.typing import com.intellij.openapi.util.RecursionManager @@ -16,9 +16,11 @@ open class ListLiteralType(val expressions: List, private val cont override fun isValid(): Boolean = context.isValid - override fun inferComponents(): List { - return expressions.flatMap { - doGetComponentTypes(it) ?: return emptyList() + override fun inferComponents(): List = myComponentTypes + + private val myComponentTypes: List = run { + expressions.flatMap { + doGetComponentTypes(it) ?: return@run emptyList() } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy index 9bab7705117d..adfa6e66a93c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy @@ -994,7 +994,7 @@ def foo() { void 'test recursive literal types'() { RecursionManager.disableMissedCacheAssertions(testRootDisposable) - doExprTest 'def foo() { [foo()] }\nfoo()', "java.util.List" + doExprTest 'def foo() { [foo()] }\nfoo()', "java.util.List" doExprTest 'def foo() { [new Object(), foo()] }\nfoo()', "java.util.List" doExprTest 'def foo() { [someKey1: foo()] }\nfoo()', "java.util.LinkedHashMap" doExprTest 'def foo() { [someKey0: new Object(), someKey1: foo()] }\nfoo()',