Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
718f23b3
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,发现更多精彩内容 >>
提交
718f23b3
编写于
6月 02, 2020
作者:
M
Mikhail Zarechenskiy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Compatibility warning for references to companion via name (KT-13934)
上级
3fdf048e
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
284 addition
and
2 deletion
+284
-2
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
...ns/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
+10
-0
compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
...ns/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
+5
-0
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt
...n/resolve/calls/components/CallableReferenceResolution.kt
+9
-2
compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt
.../callableReference/function/referenceToCompanionMember.kt
+32
-0
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt
...Reference/referenceToCompanionObjectMemberViaClassName.kt
+37
-0
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.txt
...eference/referenceToCompanionObjectMemberViaClassName.txt
+36
-0
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt
...ceToCompanionObjectMemberViaClassNameCompatibility.fir.kt
+33
-0
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt
...erenceToCompanionObjectMemberViaClassNameCompatibility.kt
+33
-0
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.txt
...renceToCompanionObjectMemberViaClassNameCompatibility.txt
+39
-0
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/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
...etbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
+5
-0
compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
...brains/kotlin/codegen/LightAnalysisModeTestGenerated.java
+5
-0
compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java
...ins/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java
+5
-0
js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
...js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
+5
-0
js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java
...lin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java
+5
-0
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java
...s/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java
+5
-0
未找到文件。
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -1939,6 +1939,16 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
}
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
public void testRewriteAtSliceOnGetOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2685,6 +2685,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt
浏览文件 @
718f23b3
...
...
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.DISPATCH_RE
import
org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.EXTENSION_RECEIVER
import
org.jetbrains.kotlin.resolve.calls.tower.*
import
org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import
org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import
org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
import
org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import
org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
...
...
@@ -213,7 +214,7 @@ class CallableReferencesCandidateFactory(
callComponents
.
builtIns
)
if
(
needCompatibilityWarning
(
callableReferenceAdaptation
))
{
if
(
needCompatibilityWarning
(
callableReferenceAdaptation
,
candidateDescriptor
))
{
diagnostics
.
add
(
LowerPriorityToPreserveCompatibility
)
}
...
...
@@ -261,7 +262,13 @@ class CallableReferencesCandidateFactory(
)
}
private
fun
needCompatibilityWarning
(
callableReferenceAdaptation
:
CallableReferenceAdaptation
?):
Boolean
{
private
fun
needCompatibilityWarning
(
callableReferenceAdaptation
:
CallableReferenceAdaptation
?,
candidate
:
CallableDescriptor
):
Boolean
{
// KT-13934: reference to companion object member via class name
if
(
candidate
.
containingDeclaration
.
isCompanionObject
()
&&
argument
.
lhsResult
is
LHSResult
.
Type
)
return
true
if
(
callableReferenceAdaptation
==
null
)
return
false
return
callableReferenceAdaptation
.
defaults
!=
0
||
...
...
compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt
0 → 100644
浏览文件 @
718f23b3
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS
class
A
{
companion
object
{
fun
foo
():
String
=
"OK"
}
}
class
B
{
companion
object
{
fun
foo
():
String
=
"Fail"
}
}
fun
B
.
foo
():
String
=
"OK"
fun
call
(
f
:
Any
):
String
=
if
(
f
is
Function0
<
*
>)
f
.
invoke
()
as
String
else
(
f
as
Function1
<
B
,
String
>).
invoke
(
B
())
fun
box
():
String
{
val
call1
=
call
(
A
::
foo
)
if
(
call1
!=
"OK"
)
return
"fail 1: $call1"
// Checking compatibility mode: should be resolved to extensions in 1.4
val
call2
=
call
(
B
::
foo
)
if
(
call2
!=
"OK"
)
return
"fail 2: $call2"
return
"OK"
}
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt
0 → 100644
浏览文件 @
718f23b3
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class
A
{
companion
object
{
fun
foo
():
Int
=
0
}
}
class
B
{
fun
foo
():
String
=
""
companion
object
{
fun
foo
():
Int
=
0
}
}
fun
<
T
>
call
(
f
:
()
->
T
):
T
=
f
()
fun
testA
(
a
:
A
)
{
val
call1
=
call
(
A
::
foo
)
<!
DEBUG_INFO_EXPRESSION_TYPE
(
"kotlin.Int"
)!>
call1
<!>
val
call2
=
call
(
A
.
Companion
::
foo
)
<!
DEBUG_INFO_EXPRESSION_TYPE
(
"kotlin.Int"
)!>
call2
<!>
}
fun
testB
(
b
:
B
)
{
val
call1
=
call
(
B
::
foo
)
<!
DEBUG_INFO_EXPRESSION_TYPE
(
"kotlin.Int"
)!>
call1
<!>
val
call2
=
call
(
B
()
::
foo
)
<!
DEBUG_INFO_EXPRESSION_TYPE
(
"kotlin.String"
)!>
call2
<!>
val
call3
=
call
(
B
.
Companion
::
foo
)
<!
DEBUG_INFO_EXPRESSION_TYPE
(
"kotlin.Int"
)!>
call3
<!>
}
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.txt
0 → 100644
浏览文件 @
718f23b3
package
public fun </*0*/ T> call(/*0*/ f: () -> T): T
public fun testA(/*0*/ a: A): kotlin.Unit
public fun testB(/*0*/ b: B): kotlin.Unit
public final class A {
public constructor A()
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 companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class B {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.fir.kt
0 → 100644
浏览文件 @
718f23b3
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class
A
{
companion
object
{
fun
foo
():
Int
=
0
}
}
fun
A
.
foo
():
Double
=
0.0
fun
Any
.
foo
():
Float
=
1f
class
B
{
fun
foo
():
String
=
""
companion
object
{
fun
foo
():
Int
=
0
}
}
fun
B
.
foo
():
Double
=
0.0
fun
call
(
a
:
Any
)
{}
fun
testA
(
a
:
A
)
{
call
(
A
::
foo
)
call
(
A
.
Companion
::
foo
)
}
fun
testB
(
b
:
B
)
{
call
(
B
::
foo
)
call
(
B
()
::
foo
)
call
(
B
.
Companion
::
foo
)
}
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt
0 → 100644
浏览文件 @
718f23b3
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER
class
A
{
companion
object
{
fun
foo
():
Int
=
0
}
}
fun
A
.
foo
():
Double
=
0.0
fun
Any
.
foo
():
Float
=
1f
class
B
{
fun
foo
():
String
=
""
companion
object
{
fun
foo
():
Int
=
0
}
}
fun
B
.<
!
EXTENSION_SHADOWED_BY_MEMBER
!
>
foo
<!>():
Double
=
0.0
fun
call
(
a
:
Any
)
{}
fun
testA
(
a
:
A
)
{
call
(<!
COMPATIBILITY_WARNING
!>
A
::
foo
<!>)
call
(
A
.
Companion
::
foo
)
}
fun
testB
(
b
:
B
)
{
call
(
B
::
foo
)
call
(
B
()
::
foo
)
call
(
B
.
Companion
::
foo
)
}
compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.txt
0 → 100644
浏览文件 @
718f23b3
package
public fun call(/*0*/ a: kotlin.Any): kotlin.Unit
public fun testA(/*0*/ a: A): kotlin.Unit
public fun testB(/*0*/ b: B): kotlin.Unit
public fun A.foo(): kotlin.Double
public fun B.foo(): kotlin.Double
public fun kotlin.Any.foo(): kotlin.Float
public final class A {
public constructor A()
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 companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public final class B {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -1946,6 +1946,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
}
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
public void testRewriteAtSliceOnGetOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -1941,6 +1941,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassName.kt")
public void testReferenceToCompanionObjectMemberViaClassName() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassName.kt");
}
@TestMetadata("referenceToCompanionObjectMemberViaClassNameCompatibility.kt")
public void testReferenceToCompanionObjectMemberViaClassNameCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/referenceToCompanionObjectMemberViaClassNameCompatibility.kt");
}
@TestMetadata("rewriteAtSliceOnGetOperator.kt")
public void testRewriteAtSliceOnGetOperator() throws Exception {
runTest("compiler/testData/diagnostics/tests/callableReference/rewriteAtSliceOnGetOperator.kt");
compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2705,6 +2705,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2705,6 +2705,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2685,6 +2685,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2065,6 +2065,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2075,6 +2075,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java
浏览文件 @
718f23b3
...
...
@@ -2075,6 +2075,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/function/privateClassMember.kt");
}
@TestMetadata("referenceToCompanionMember.kt")
public void testReferenceToCompanionMember() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt");
}
@TestMetadata("sortListOfStrings.kt")
public void testSortListOfStrings() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt");
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录