Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
5f9357eb
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5f9357eb
编写于
2月 09, 2021
作者:
J
Jinseong Jeon
提交者:
Mikhail Glukhikh
2月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIR: transform implicit type ref in anonymous function arguments & body
^KT-45010 Fixed
上级
a841a0bb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
59 addition
and
1 deletion
+59
-1
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java
.../test/runners/FirOldFrontendDiagnosticsTestGenerated.java
+6
-0
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt
...transformers/FirCallCompletionResultsWriterTransformer.kt
+32
-1
compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.fir.kt
...ithStdLib/resolve/lambdaArgumentOfInapplicableCall.fir.kt
+6
-0
compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.kt
...stsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.kt
+6
-0
compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.txt
...tsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.txt
+3
-0
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
...etbrains/kotlin/test/runners/DiagnosticTestGenerated.java
+6
-0
未找到文件。
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java
浏览文件 @
5f9357eb
...
@@ -34693,6 +34693,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
...
@@ -34693,6 +34693,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.kt");
runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.kt");
}
}
@Test
@TestMetadata("lambdaArgumentOfInapplicableCall.kt")
public void testLambdaArgumentOfInapplicableCall() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.kt");
}
@Test
@Test
@TestMetadata("samAgainstFunctionalType.kt")
@TestMetadata("samAgainstFunctionalType.kt")
public void testSamAgainstFunctionalType() throws Exception {
public void testSamAgainstFunctionalType() throws Exception {
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt
浏览文件 @
5f9357eb
...
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
...
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import
org.jetbrains.kotlin.fir.*
import
org.jetbrains.kotlin.fir.*
import
org.jetbrains.kotlin.fir.declarations.*
import
org.jetbrains.kotlin.fir.declarations.*
import
org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import
org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import
org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import
org.jetbrains.kotlin.fir.expressions.*
import
org.jetbrains.kotlin.fir.expressions.*
import
org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference
import
org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference
import
org.jetbrains.kotlin.fir.references.builder.buildResolvedCallableReference
import
org.jetbrains.kotlin.fir.references.builder.buildResolvedCallableReference
...
@@ -436,7 +437,10 @@ class FirCallCompletionResultsWriterTransformer(
...
@@ -436,7 +437,10 @@ class FirCallCompletionResultsWriterTransformer(
// Control flow info is necessary prerequisite because we collect return expressions in that function
// Control flow info is necessary prerequisite because we collect return expressions in that function
//
//
// Example: second lambda in the call like list.filter({}, {})
// Example: second lambda in the call like list.filter({}, {})
if
(!
dataFlowAnalyzer
.
isThereControlFlowInfoForAnonymousFunction
(
anonymousFunction
))
return
anonymousFunction
.
compose
()
if
(!
dataFlowAnalyzer
.
isThereControlFlowInfoForAnonymousFunction
(
anonymousFunction
))
{
// But, don't leave implicit type refs behind
return
transformImplicitTypeRefInAnonymousFunction
(
anonymousFunction
)
}
val
expectedType
=
data
?.
getExpectedType
(
anonymousFunction
)
?.
let
{
expectedArgumentType
->
val
expectedType
=
data
?.
getExpectedType
(
anonymousFunction
)
?.
let
{
expectedArgumentType
->
// From the argument mapping, the expected type of this anonymous function would be:
// From the argument mapping, the expected type of this anonymous function would be:
...
@@ -509,6 +513,33 @@ class FirCallCompletionResultsWriterTransformer(
...
@@ -509,6 +513,33 @@ class FirCallCompletionResultsWriterTransformer(
return
result
return
result
}
}
private
fun
transformImplicitTypeRefInAnonymousFunction
(
anonymousFunction
:
FirAnonymousFunction
):
CompositeTransformResult
<
FirStatement
>
{
val
implicitTypeTransformer
=
object
:
FirDefaultTransformer
<
Nothing
?>()
{
override
fun
<
E
:
FirElement
>
transformElement
(
element
:
E
,
data
:
Nothing
?):
CompositeTransformResult
<
E
>
{
@Suppress
(
"UNCHECKED_CAST"
)
return
(
element
.
transformChildren
(
this
,
data
)
as
E
).
compose
()
}
override
fun
transformImplicitTypeRef
(
implicitTypeRef
:
FirImplicitTypeRef
,
data
:
Nothing
?
):
CompositeTransformResult
<
FirTypeRef
>
=
buildErrorTypeRef
{
source
=
implicitTypeRef
.
source
// NB: this error message assumes that it is used only if CFG for the anonymous function is not available
diagnostic
=
ConeSimpleDiagnostic
(
"Cannot infer type w/o CFG"
,
DiagnosticKind
.
InferenceError
)
}.
compose
()
}
// NB: if we transform simply all children, there would be too many type error reports.
anonymousFunction
.
transformReturnTypeRef
(
implicitTypeTransformer
,
null
)
anonymousFunction
.
transformValueParameters
(
implicitTypeTransformer
,
null
)
anonymousFunction
.
transformBody
(
implicitTypeTransformer
,
null
)
return
anonymousFunction
.
compose
()
}
override
fun
transformReturnExpression
(
override
fun
transformReturnExpression
(
returnExpression
:
FirReturnExpression
,
returnExpression
:
FirReturnExpression
,
data
:
ExpectedArgumentType
?
data
:
ExpectedArgumentType
?
...
...
compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.fir.kt
0 → 100644
浏览文件 @
5f9357eb
// KT-45010
fun
foo
(
map
:
MutableMap
<
Int
,
String
>)
{
map
.<!
INAPPLICABLE_CANDIDATE
!>
getOrPut
<!>(
"Not an Int"
)
{
"Hello"
+
" world"
}
}
compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.kt
0 → 100644
浏览文件 @
5f9357eb
// KT-45010
fun
foo
(
map
:
MutableMap
<
Int
,
String
>)
{
map
.
getOrPut
(<!
TYPE_MISMATCH
!>
"Not an Int"
<!>)
{
"Hello"
+
" world"
}
}
compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.txt
0 → 100644
浏览文件 @
5f9357eb
package
public fun foo(/*0*/ map: kotlin.collections.MutableMap<kotlin.Int, kotlin.String>): kotlin.Unit
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
浏览文件 @
5f9357eb
...
@@ -34789,6 +34789,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
...
@@ -34789,6 +34789,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.kt");
runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/kt4711.kt");
}
}
@Test
@TestMetadata("lambdaArgumentOfInapplicableCall.kt")
public void testLambdaArgumentOfInapplicableCall() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/lambdaArgumentOfInapplicableCall.kt");
}
@Test
@Test
@TestMetadata("samAgainstFunctionalType.kt")
@TestMetadata("samAgainstFunctionalType.kt")
public void testSamAgainstFunctionalType() throws Exception {
public void testSamAgainstFunctionalType() throws Exception {
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录