Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
df1595e4
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,发现更多精彩内容 >>
提交
df1595e4
编写于
6月 15, 2020
作者:
M
Mikhail Zarechenskiy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix SAM conversions for derived classes
#KT-39535 Fixed #KT-37149 Fixed
上级
ee6d432c
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
171 addition
and
50 deletion
+171
-50
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
...ns/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
+10
-0
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SamTypeConversions.kt
...ins/kotlin/resolve/calls/components/SamTypeConversions.kt
+12
-9
compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt
...ics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt
+22
-0
compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.kt
...nostics/tests/j+k/sam/conversionForDerivedGenericClass.kt
+22
-0
compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.txt
...ostics/tests/j+k/sam/conversionForDerivedGenericClass.txt
+28
-0
compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.kt
...iagnostics/tests/j+k/sam/conversionsWithNestedGenerics.kt
+22
-0
compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.txt
...agnostics/tests/j+k/sam/conversionsWithNestedGenerics.txt
+27
-0
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.fir.kt
...gnostics/tests/samConversions/SAMAfterSubstitution.fir.kt
+0
-18
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.kt
.../diagnostics/tests/samConversions/SAMAfterSubstitution.kt
+4
-3
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt
...ostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt
+0
-17
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.kt
...iagnostics/tests/samConversions/SAMAfterSubstitutionKT.kt
+4
-3
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
...g/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
+10
-0
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
...in/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
+10
-0
未找到文件。
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
浏览文件 @
df1595e4
...
...
@@ -13661,6 +13661,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt");
}
@TestMetadata("conversionForDerivedGenericClass.kt")
public void testConversionForDerivedGenericClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.kt");
}
@TestMetadata("conversionsWithNestedGenerics.kt")
public void testConversionsWithNestedGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.kt");
}
@TestMetadata("enhancedSamConstructor.kt")
public void testEnhancedSamConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.kt");
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SamTypeConversions.kt
浏览文件 @
df1595e4
...
...
@@ -64,19 +64,22 @@ object SamTypeConversions : ParameterTypeConversion {
val
callComponents
=
candidate
.
callComponents
val
originalExpectedType
=
argument
.
getExpectedType
(
parameter
.
original
,
callComponents
.
languageVersionSettings
)
val
convertedTypeByOriginal
=
callComponents
.
samConversionResolver
.
getFunctionTypeForPossibleSamType
(
originalExpectedType
,
callComponents
.
samConversionOracle
)
?:
return
null
val
convertedTypeByCandidate
=
callComponents
.
samConversionResolver
.
getFunctionTypeForPossibleSamType
(
expectedParameterType
,
callComponents
.
samConversionOracle
)
)
?:
return
null
assert
(
expectedParameterType
.
constructor
==
originalExpectedType
.
constructor
&&
convertedTypeByCandidate
!=
null
)
{
val
convertedTypeByOriginal
=
if
(
expectedParameterType
.
constructor
==
originalExpectedType
.
constructor
)
callComponents
.
samConversionResolver
.
getFunctionTypeForPossibleSamType
(
originalExpectedType
,
callComponents
.
samConversionOracle
)
else
convertedTypeByCandidate
assert
(
convertedTypeByCandidate
.
constructor
==
convertedTypeByOriginal
?.
constructor
)
{
"If original type is SAM type, then candidate should have same type constructor and corresponding function type\n"
+
"originalExpectType: $originalExpectedType, candidateExpectType: $expectedParameterType\n"
+
"functionTypeByOriginal: $convertedTypeByOriginal, functionTypeByCandidate: $convertedTypeByCandidate"
...
...
@@ -84,7 +87,7 @@ object SamTypeConversions : ParameterTypeConversion {
candidate
.
resolvedCall
.
registerArgumentWithSamConversion
(
argument
,
SamConversionDescription
(
convertedTypeByOriginal
,
convertedTypeByCandidate
!!
)
SamConversionDescription
(
convertedTypeByOriginal
!!
,
convertedTypeByCandidate
)
)
if
(
needCompatibilityResolveForSAM
(
candidate
,
expectedParameterType
))
{
...
...
compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.fir.kt
0 → 100644
浏览文件 @
df1595e4
// FILE: A.java
public
interface
A
<
T
>
{
void
f
(
T
arg
);
}
// FILE: B.java
public
interface
B
extends
A
<
Runnable
>
{}
// FILE: C.java
public
class
C
<
K
>
{
public
void
f
(
K
k
)
{}
public
static
<
R
>
void
g
(
R
r
)
{}
}
// FILE: test.kt
fun
test
(
a
:
A
<
Runnable
>,
b
:
B
,
c
:
C
<
Runnable
>)
{
a
.
f
{
}
b
.
f
{
}
c
.
f
{
}
C
<
Runnable
>().
f
{
}
C
.
g
<
Runnable
>
{
}
}
\ No newline at end of file
compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.kt
0 → 100644
浏览文件 @
df1595e4
// FILE: A.java
public
interface
A
<
T
>
{
void
f
(
T
arg
);
}
// FILE: B.java
public
interface
B
extends
A
<
Runnable
>
{}
// FILE: C.java
public
class
C
<
K
>
{
public
void
f
(
K
k
)
{}
public
static
<
R
>
void
g
(
R
r
)
{}
}
// FILE: test.kt
fun
test
(
a
:
A
<
Runnable
>,
b
:
B
,
c
:
C
<
Runnable
>)
{
a
.
f
{
}
b
.
f
{
}
c
.
f
{
}
C
<
Runnable
>().
f
{
}
C
.
g
<
Runnable
>
<!
TYPE_MISMATCH
,
TYPE_MISMATCH
!>{
}<!>
}
\ No newline at end of file
compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.txt
0 → 100644
浏览文件 @
df1595e4
package
public fun test(/*0*/ a: A<java.lang.Runnable>, /*1*/ b: B, /*2*/ c: C<java.lang.Runnable>): kotlin.Unit
public interface A</*0*/ T : kotlin.Any!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun f(/*0*/ arg: T!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface B : A<java.lang.Runnable!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*1*/ /*fake_override*/ fun f(/*0*/ arg: java.lang.Runnable!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class C</*0*/ K : kotlin.Any!> {
public constructor C</*0*/ K : kotlin.Any!>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open fun f(/*0*/ k: K!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public open fun </*0*/ R : kotlin.Any!> g(/*0*/ r: R!): kotlin.Unit
}
compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.kt
0 → 100644
浏览文件 @
df1595e4
// FIR_IDENTICAL
// FILE: Listener.java
public
interface
Listener
<
T
>
{
void
on
(
T
self
);
}
// FILE: Base.java
public
class
Base
<
S
,
T
extends
Listener
<
S
>>
{
public
void
addListener
(
T
listener
)
{}
}
// FILE: Derived.java
public
class
Derived
extends
Base
<
Derived
,
Listener
<
Derived
>>
{}
// FILE: test.kt
fun
test
(
w
:
Derived
)
{
w
.
addListener
{
_
->
call
()
}
}
fun
call
()
{}
\ No newline at end of file
compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.txt
0 → 100644
浏览文件 @
df1595e4
package
public fun call(): kotlin.Unit
public fun test(/*0*/ w: Derived): kotlin.Unit
public open class Base</*0*/ S : kotlin.Any!, /*1*/ T : Listener<S!>!> {
public constructor Base</*0*/ S : kotlin.Any!, /*1*/ T : Listener<S!>!>()
public open fun addListener(/*0*/ listener: T!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class Derived : Base<Derived!, Listener<Derived!>!> {
public constructor Derived()
public open override /*1*/ /*fake_override*/ fun addListener(/*0*/ listener: Listener<Derived!>!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Listener</*0*/ T : kotlin.Any!> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public abstract fun on(/*0*/ self: T!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.fir.kt
已删除
100644 → 0
浏览文件 @
ee6d432c
// !LANGUAGE: +NewInference
// FILE: J.java
public
interface
J
<
T
>
{
public
void
foo
(
T
r1
,
T
r2
);
}
// FILE: Runnable.java
public
interface
Runnable
{
void
run
();
}
// FILE: 1.kt
fun
test
(
j
:
J
<
Runnable
>,
r
:
Runnable
)
{
j
.
foo
(
r
,
r
)
j
.
foo
(
r
,
{})
j
.
foo
({},
r
)
j
.
foo
({},
{})
}
\ No newline at end of file
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitution.kt
浏览文件 @
df1595e4
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// FILE: J.java
public
interface
J
<
T
>
{
...
...
@@ -12,7 +13,7 @@ public interface Runnable {
// FILE: 1.kt
fun
test
(
j
:
J
<
Runnable
>,
r
:
Runnable
)
{
j
.
foo
(
r
,
r
)
j
.
foo
(
r
,
<!
TYPE_MISMATCH
!>{}<!>
)
j
.
foo
(
<!
TYPE_MISMATCH
!>{}<!>
,
r
)
j
.
foo
(
<!
TYPE_MISMATCH
!>{}<!>,
<!
TYPE_MISMATCH
!>{}<!>
)
j
.
foo
(
r
,
{}
)
j
.
foo
(
{}
,
r
)
j
.
foo
(
{},
{}
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.fir.kt
已删除
100644 → 0
浏览文件 @
ee6d432c
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// FILE: Runnable.java
public
interface
Runnable
{
void
run
();
}
// FILE: 1.kt
interface
K
<
T
>
{
fun
foo
(
t1
:
T
,
t2
:
T
)
}
fun
test
(
k
:
K
<
Runnable
>,
r
:
Runnable
)
{
k
.
foo
(
r
,
r
)
k
.
foo
(
r
,
{})
k
.
foo
({},
r
)
k
.
foo
({},
{})
}
\ No newline at end of file
compiler/testData/diagnostics/tests/samConversions/SAMAfterSubstitutionKT.kt
浏览文件 @
df1595e4
// FIR_IDENTICAL
// !LANGUAGE: +NewInference +SamConversionForKotlinFunctions
// FILE: Runnable.java
public
interface
Runnable
{
...
...
@@ -11,7 +12,7 @@ interface K<T> {
fun
test
(
k
:
K
<
Runnable
>,
r
:
Runnable
)
{
k
.
foo
(
r
,
r
)
k
.
foo
(
r
,
<!
TYPE_MISMATCH
!>{}<!>
)
k
.
foo
(
<!
TYPE_MISMATCH
!>{}<!>
,
r
)
k
.
foo
(
<!
TYPE_MISMATCH
!>{}<!>,
<!
TYPE_MISMATCH
!>{}<!>
)
k
.
foo
(
r
,
{}
)
k
.
foo
(
{}
,
r
)
k
.
foo
(
{},
{}
)
}
\ No newline at end of file
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
浏览文件 @
df1595e4
...
...
@@ -13668,6 +13668,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt");
}
@TestMetadata("conversionForDerivedGenericClass.kt")
public void testConversionForDerivedGenericClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.kt");
}
@TestMetadata("conversionsWithNestedGenerics.kt")
public void testConversionsWithNestedGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.kt");
}
@TestMetadata("enhancedSamConstructor.kt")
public void testEnhancedSamConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.kt");
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
浏览文件 @
df1595e4
...
...
@@ -13663,6 +13663,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt");
}
@TestMetadata("conversionForDerivedGenericClass.kt")
public void testConversionForDerivedGenericClass() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/conversionForDerivedGenericClass.kt");
}
@TestMetadata("conversionsWithNestedGenerics.kt")
public void testConversionsWithNestedGenerics() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/conversionsWithNestedGenerics.kt");
}
@TestMetadata("enhancedSamConstructor.kt")
public void testEnhancedSamConstructor() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.kt");
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录