Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
71cbe976
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,发现更多精彩内容 >>
提交
71cbe976
编写于
6月 02, 2020
作者:
M
Mikhail Zarechenskiy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce `Unit`-conversions for simple arguments
上级
f08a45f2
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
484 addition
and
6 deletion
+484
-6
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
...ns/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
+43
-0
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/UnitTypeConversions.kt
...ns/kotlin/resolve/calls/components/UnitTypeConversions.kt
+83
-0
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/typeConversions.kt
...brains/kotlin/resolve/calls/components/typeConversions.kt
+18
-6
compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.fir.kt
...sts/unitConversion/chainedFunSuspendUnitConversion.fir.kt
+18
-0
compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.kt
...s/tests/unitConversion/chainedFunSuspendUnitConversion.kt
+18
-0
compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.txt
.../tests/unitConversion/chainedFunSuspendUnitConversion.txt
+20
-0
compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.fir.kt
...tics/tests/unitConversion/chainedFunUnitConversion.fir.kt
+15
-0
compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.kt
...gnostics/tests/unitConversion/chainedFunUnitConversion.kt
+15
-0
compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.txt
...nostics/tests/unitConversion/chainedFunUnitConversion.txt
+19
-0
compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.fir.kt
.../tests/unitConversion/chainedUnitSuspendConversion.fir.kt
+14
-0
compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.kt
...tics/tests/unitConversion/chainedUnitSuspendConversion.kt
+14
-0
compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.txt
...ics/tests/unitConversion/chainedUnitSuspendConversion.txt
+13
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionCompatibility.kt
...stics/tests/unitConversion/unitConversionCompatibility.kt
+0
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.fir.kt
...ics/tests/unitConversion/unitConversionForAllKinds.fir.kt
+16
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.kt
...nostics/tests/unitConversion/unitConversionForAllKinds.kt
+16
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.txt
...ostics/tests/unitConversion/unitConversionForAllKinds.txt
+7
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.fir.kt
...ics/tests/unitConversion/unitConversionForSubtypes.fir.kt
+22
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.kt
...nostics/tests/unitConversion/unitConversionForSubtypes.kt
+22
-0
compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.txt
...ostics/tests/unitConversion/unitConversionForSubtypes.txt
+21
-0
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
...g/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
+43
-0
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
...in/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
+43
-0
compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt
...rc/org/jetbrains/kotlin/config/LanguageVersionSettings.kt
+1
-0
core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt
...iptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt
+3
-0
未找到文件。
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
浏览文件 @
71cbe976
...
@@ -24444,6 +24444,49 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
...
@@ -24444,6 +24444,49 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
}
}
}
}
@TestMetadata("compiler/testData/diagnostics/tests/unitConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnitConversion extends AbstractFirOldFrontendDiagnosticsTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInUnitConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/unitConversion"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("chainedFunSuspendUnitConversion.kt")
public void testChainedFunSuspendUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.kt");
}
@TestMetadata("chainedFunUnitConversion.kt")
public void testChainedFunUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.kt");
}
@TestMetadata("chainedUnitSuspendConversion.kt")
public void testChainedUnitSuspendConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.kt");
}
@TestMetadata("unitConversionCompatibility.kt")
public void testUnitConversionCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionCompatibility.kt");
}
@TestMetadata("unitConversionForAllKinds.kt")
public void testUnitConversionForAllKinds() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.kt");
}
@TestMetadata("unitConversionForSubtypes.kt")
public void testUnitConversionForSubtypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestDataPath("$PROJECT_ROOT")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@RunWith(JUnit3RunnerWithInners.class)
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/UnitTypeConversions.kt
0 → 100644
浏览文件 @
71cbe976
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package
org.jetbrains.kotlin.resolve.calls.components
import
org.jetbrains.kotlin.builtins.*
import
org.jetbrains.kotlin.descriptors.ParameterDescriptor
import
org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
import
org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
import
org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
import
org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
import
org.jetbrains.kotlin.types.KotlinType
import
org.jetbrains.kotlin.types.UnwrappedType
import
org.jetbrains.kotlin.types.isDynamic
import
org.jetbrains.kotlin.types.typeUtil.isUnit
object
UnitTypeConversions
:
ParameterTypeConversion
{
override
fun
conversionDefinitelyNotNeeded
(
candidate
:
KotlinResolutionCandidate
,
argument
:
KotlinCallArgument
,
expectedParameterType
:
UnwrappedType
):
Boolean
{
// for callable references and lambdas it already works
if
(
argument
!
is
SimpleKotlinCallArgument
)
return
true
val
receiver
=
argument
.
receiver
if
(
receiver
.
receiverValue
.
type
.
hasUnitOrDynamicReturnType
())
return
true
if
(
receiver
.
typesFromSmartCasts
.
any
{
it
.
hasUnitOrDynamicReturnType
()
})
return
true
if
(
!
expectedParameterType
.
isBuiltinFunctionalType
||
!
expectedParameterType
.
getReturnTypeFromFunctionType
().
isUnit
()
)
return
true
return
false
}
private
fun
KotlinType
.
hasUnitOrDynamicReturnType
():
Boolean
=
isFunctionOrKFunctionTypeWithAnySuspendability
&&
arguments
.
last
().
type
.
isUnitOrDynamic
()
private
fun
KotlinType
.
isUnitOrDynamic
():
Boolean
=
isUnit
()
||
isDynamic
()
override
fun
conversionIsNeededBeforeSubtypingCheck
(
argument
:
KotlinCallArgument
):
Boolean
=
argument
is
SimpleKotlinCallArgument
&&
argument
.
receiver
.
stableType
.
isFunctionType
override
fun
conversionIsNeededAfterSubtypingCheck
(
argument
:
KotlinCallArgument
):
Boolean
{
if
(
argument
!
is
SimpleKotlinCallArgument
)
return
false
var
isFunctionTypeOrSubtype
=
false
val
hasReturnTypeInSubtypes
=
argument
.
receiver
.
stableType
.
isFunctionTypeOrSubtype
{
isFunctionTypeOrSubtype
=
true
it
.
getReturnTypeFromFunctionType
().
isUnitOrDynamic
()
}
if
(!
isFunctionTypeOrSubtype
)
return
false
return
!
hasReturnTypeInSubtypes
}
override
fun
convertParameterType
(
candidate
:
KotlinResolutionCandidate
,
argument
:
KotlinCallArgument
,
parameter
:
ParameterDescriptor
,
expectedParameterType
:
UnwrappedType
):
UnwrappedType
?
{
val
nonUnitReturnedParameterType
=
createFunctionType
(
candidate
.
callComponents
.
builtIns
,
expectedParameterType
.
annotations
,
expectedParameterType
.
getReceiverTypeFromFunctionType
(),
expectedParameterType
.
getValueParameterTypesFromFunctionType
().
map
{
it
.
type
},
parameterNames
=
null
,
candidate
.
callComponents
.
builtIns
.
nullableAnyType
,
suspendFunction
=
expectedParameterType
.
isSuspendFunctionType
)
candidate
.
addDiagnostic
(
LowerPriorityToPreserveCompatibility
)
return
nonUnitReturnedParameterType
}
}
\ No newline at end of file
compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/typeConversions.kt
浏览文件 @
71cbe976
...
@@ -40,14 +40,23 @@ object TypeConversions {
...
@@ -40,14 +40,23 @@ object TypeConversions {
)
)
val
suspendConversionData
=
performConversionBeforeSubtyping
(
val
suspendConversionData
=
performConversionBeforeSubtyping
(
candidate
,
argument
,
candidateParameter
,
samConversionData
.
convertedType
?:
candidateExpectedType
,
SuspendTypeConversions
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
=
samConversionData
.
convertedType
?:
candidateExpectedType
,
SuspendTypeConversions
)
val
unitConversionData
=
performConversionBeforeSubtyping
(
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
=
suspendConversionData
.
convertedType
?:
samConversionData
.
convertedType
?:
candidateExpectedType
,
UnitTypeConversions
)
)
return
ConversionData
(
return
ConversionData
(
convertedType
=
suspendConversionData
.
convertedType
?:
samConversionData
.
convertedType
,
convertedType
=
unitConversionData
.
convertedType
?:
suspendConversionData
.
convertedType
?:
samConversionData
.
convertedType
,
wasConversion
=
samConversionData
.
wasConversion
||
suspendConversionData
.
wasConversion
,
wasConversion
=
samConversionData
.
wasConversion
||
suspendConversionData
.
wasConversion
||
unitConversionData
.
wasConversion
,
conversionDefinitelyNotNeeded
=
samConversionData
.
conversionDefinitelyNotNeeded
&&
conversionDefinitelyNotNeeded
=
samConversionData
.
conversionDefinitelyNotNeeded
&&
suspendConversionData
.
conversionDefinitelyNotNeeded
suspendConversionData
.
conversionDefinitelyNotNeeded
&&
unitConversionData
.
conversionDefinitelyNotNeeded
)
)
}
}
...
@@ -60,10 +69,13 @@ object TypeConversions {
...
@@ -60,10 +69,13 @@ object TypeConversions {
val
samConvertedType
=
performConversionAfterSubtyping
(
val
samConvertedType
=
performConversionAfterSubtyping
(
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
,
SamTypeConversions
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
,
SamTypeConversions
)
)
if
(
samConvertedType
!=
null
)
return
samConvertedType
if
(
samConvertedType
!=
null
)
return
samConvertedType
return
performConversionAfterSubtyping
(
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
,
SuspendTypeConversions
)
val
suspendConvertedType
=
performConversionAfterSubtyping
(
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
,
SuspendTypeConversions
)
if
(
suspendConvertedType
!=
null
)
return
suspendConvertedType
return
performConversionAfterSubtyping
(
candidate
,
argument
,
candidateParameter
,
candidateExpectedType
,
UnitTypeConversions
)
}
}
private
fun
performConversionAfterSubtyping
(
private
fun
performConversionAfterSubtyping
(
...
...
compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.fir.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
interface
SuspendRunnable
{
suspend
fun
run
()
}
fun
foo
(
r
:
SuspendRunnable
)
{}
fun
bar
():
String
=
""
abstract
class
SubInt
:
()
->
Int
fun
test
(
f
:
()
->
String
,
s
:
SubInt
)
{
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
f
)
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
s
)
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
::
bar
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
interface
SuspendRunnable
{
suspend
fun
run
()
}
fun
foo
(
r
:
SuspendRunnable
)
{}
fun
bar
():
String
=
""
abstract
class
SubInt
:
()
->
Int
fun
test
(
f
:
()
->
String
,
s
:
SubInt
)
{
foo
(
f
)
foo
(
s
)
foo
(
::
bar
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.txt
0 → 100644
浏览文件 @
71cbe976
package
public fun bar(): kotlin.String
public fun foo(/*0*/ r: SuspendRunnable): kotlin.Unit
public fun test(/*0*/ f: () -> kotlin.String, /*1*/ s: SubInt): kotlin.Unit
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
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 override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public fun interface SuspendRunnable {
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 suspend fun run(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.fir.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
interface
KRunnable
{
fun
run
()
}
fun
foo
(
r
:
KRunnable
)
{}
abstract
class
SubInt
:
()
->
Int
fun
test
(
f
:
()
->
Int
,
s
:
SubInt
)
{
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
f
)
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
s
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
interface
KRunnable
{
fun
run
()
}
fun
foo
(
r
:
KRunnable
)
{}
abstract
class
SubInt
:
()
->
Int
fun
test
(
f
:
()
->
Int
,
s
:
SubInt
)
{
foo
(
f
)
foo
(
s
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.txt
0 → 100644
浏览文件 @
71cbe976
package
public fun foo(/*0*/ r: KRunnable): kotlin.Unit
public fun test(/*0*/ f: () -> kotlin.Int, /*1*/ s: SubInt): kotlin.Unit
public fun interface KRunnable {
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 run(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
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 override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.fir.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
foo
(
f
:
suspend
()
->
Unit
)
{}
fun
bar
():
String
=
""
abstract
class
SubInt
:
()
->
Int
fun
test
(
g
:
()
->
Double
,
s
:
SubInt
)
{
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
::
bar
)
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
g
)
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
s
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion +SuspendConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
foo
(
f
:
suspend
()
->
Unit
)
{}
fun
bar
():
String
=
""
abstract
class
SubInt
:
()
->
Int
fun
test
(
g
:
()
->
Double
,
s
:
SubInt
)
{
foo
(
::
bar
)
foo
(
g
)
foo
(
s
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.txt
0 → 100644
浏览文件 @
71cbe976
package
public fun bar(): kotlin.String
public fun foo(/*0*/ f: suspend () -> kotlin.Unit): kotlin.Unit
public fun test(/*0*/ g: () -> kotlin.Double, /*1*/ s: SubInt): kotlin.Unit
public abstract class SubInt : () -> kotlin.Int {
public constructor SubInt()
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 override /*1*/ /*fake_override*/ fun invoke(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
compiler/testData/diagnostics/tests/unitConversion/unitConversionCompatibility.kt
0 → 100644
浏览文件 @
71cbe976
compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.fir.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
foo
(
f
:
()
->
Unit
)
{}
fun
<
T
>
fooGeneric
(
f
:
(
T
)
->
Unit
):
T
=
TODO
()
fun
bar
():
String
=
""
fun
createCall
():
()
->
Int
=
TODO
()
fun
test
(
g
:
()
->
String
,
h
:
(
Float
)
->
String
)
{
foo
(
::
bar
)
foo
{
"something"
}
foo
(
g
)
fooGeneric
(
h
)
}
compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
foo
(
f
:
()
->
Unit
)
{}
fun
<
T
>
fooGeneric
(
f
:
(
T
)
->
Unit
):
T
=
TODO
()
fun
bar
():
String
=
""
fun
createCall
():
()
->
Int
=
TODO
()
fun
test
(
g
:
()
->
String
,
h
:
(
Float
)
->
String
)
{
foo
(
::
bar
)
foo
{
"something"
}
foo
(
g
)
<!
DEBUG_INFO_EXPRESSION_TYPE
(
"kotlin.Float"
)!>
fooGeneric
(
h
)<!>
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.txt
0 → 100644
浏览文件 @
71cbe976
package
public fun bar(): kotlin.String
public fun createCall(): () -> kotlin.Int
public fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
public fun </*0*/ T> fooGeneric(/*0*/ f: (T) -> kotlin.Unit): T
public fun test(/*0*/ g: () -> kotlin.String, /*1*/ h: (kotlin.Float) -> kotlin.String): kotlin.Unit
compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.fir.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
foo
(
f
:
(
Int
,
String
)
->
Unit
)
{}
abstract
class
SubInt
:
(
Int
,
String
)
->
Int
abstract
class
SubIntWrong
:
(
String
,
String
)
->
Int
fun
test1
(
s
:
SubInt
,
sWrong
:
SubIntWrong
)
{
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
s
)
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
sWrong
)
val
a
=
"foo"
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
a
)
a
as
(
Int
,
String
)
->
String
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
a
)
}
fun
<
T
>
test2
(
x
:
T
)
where
T
:
(
Int
,
String
)
->
Int
,
T
:
(
Double
)
->
Int
{
<!
INAPPLICABLE_CANDIDATE
!>
foo
<!>(
x
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.kt
0 → 100644
浏览文件 @
71cbe976
// !LANGUAGE: +UnitConversion
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
fun
foo
(
f
:
(
Int
,
String
)
->
Unit
)
{}
abstract
class
SubInt
:
(
Int
,
String
)
->
Int
abstract
class
SubIntWrong
:
(
String
,
String
)
->
Int
fun
test1
(
s
:
SubInt
,
sWrong
:
SubIntWrong
)
{
foo
(
s
)
foo
(<!
TYPE_MISMATCH
!>
sWrong
<!>)
val
a
=
"foo"
foo
(<!
TYPE_MISMATCH
!>
a
<!>)
a
<!
CAST_NEVER_SUCCEEDS
!>
as
<!>
(
Int
,
String
)
->
String
foo
(
a
)
}
fun
<
T
>
test2
(
x
:
T
)
where
T
:
(
Int
,
String
)
->
Int
,
T
:
(
Double
)
->
Int
{
foo
(
x
)
}
\ No newline at end of file
compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.txt
0 → 100644
浏览文件 @
71cbe976
package
public fun foo(/*0*/ f: (kotlin.Int, kotlin.String) -> kotlin.Unit): kotlin.Unit
public fun test1(/*0*/ s: SubInt, /*1*/ sWrong: SubIntWrong): kotlin.Unit
public fun </*0*/ T : (kotlin.Int, kotlin.String) -> kotlin.Int> test2(/*0*/ x: T): kotlin.Unit where T : (kotlin.Double) -> kotlin.Int
public abstract class SubInt : (kotlin.Int, kotlin.String) -> kotlin.Int {
public constructor SubInt()
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 override /*1*/ /*fake_override*/ fun invoke(/*0*/ p1: kotlin.Int, /*1*/ p2: kotlin.String): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class SubIntWrong : (kotlin.String, kotlin.String) -> kotlin.Int {
public constructor SubIntWrong()
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 override /*1*/ /*fake_override*/ fun invoke(/*0*/ p1: kotlin.String, /*1*/ p2: kotlin.String): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
浏览文件 @
71cbe976
...
@@ -24526,6 +24526,49 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
...
@@ -24526,6 +24526,49 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
}
}
}
}
@TestMetadata("compiler/testData/diagnostics/tests/unitConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnitConversion extends AbstractDiagnosticsTestWithFirValidation {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInUnitConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/unitConversion"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("chainedFunSuspendUnitConversion.kt")
public void testChainedFunSuspendUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.kt");
}
@TestMetadata("chainedFunUnitConversion.kt")
public void testChainedFunUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.kt");
}
@TestMetadata("chainedUnitSuspendConversion.kt")
public void testChainedUnitSuspendConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.kt");
}
@TestMetadata("unitConversionCompatibility.kt")
public void testUnitConversionCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionCompatibility.kt");
}
@TestMetadata("unitConversionForAllKinds.kt")
public void testUnitConversionForAllKinds() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.kt");
}
@TestMetadata("unitConversionForSubtypes.kt")
public void testUnitConversionForSubtypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestDataPath("$PROJECT_ROOT")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@RunWith(JUnit3RunnerWithInners.class)
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java
浏览文件 @
71cbe976
...
@@ -24446,6 +24446,49 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
...
@@ -24446,6 +24446,49 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
}
}
}
}
@TestMetadata("compiler/testData/diagnostics/tests/unitConversion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class UnitConversion extends AbstractDiagnosticsUsingJavacTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInUnitConversion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/unitConversion"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@TestMetadata("chainedFunSuspendUnitConversion.kt")
public void testChainedFunSuspendUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunSuspendUnitConversion.kt");
}
@TestMetadata("chainedFunUnitConversion.kt")
public void testChainedFunUnitConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedFunUnitConversion.kt");
}
@TestMetadata("chainedUnitSuspendConversion.kt")
public void testChainedUnitSuspendConversion() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/chainedUnitSuspendConversion.kt");
}
@TestMetadata("unitConversionCompatibility.kt")
public void testUnitConversionCompatibility() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionCompatibility.kt");
}
@TestMetadata("unitConversionForAllKinds.kt")
public void testUnitConversionForAllKinds() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForAllKinds.kt");
}
@TestMetadata("unitConversionForSubtypes.kt")
public void testUnitConversionForSubtypes() throws Exception {
runTest("compiler/testData/diagnostics/tests/unitConversion/unitConversionForSubtypes.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestMetadata("compiler/testData/diagnostics/tests/varargs")
@TestDataPath("$PROJECT_ROOT")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@RunWith(JUnit3RunnerWithInners.class)
compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt
浏览文件 @
71cbe976
...
@@ -153,6 +153,7 @@ enum class LanguageFeature(
...
@@ -153,6 +153,7 @@ enum class LanguageFeature(
FunctionReferenceWithDefaultValueAsOtherType
(
sinceVersion
=
KOTLIN_1_4
),
FunctionReferenceWithDefaultValueAsOtherType
(
sinceVersion
=
KOTLIN_1_4
),
NonStrictOnlyInputTypesChecks
(
sinceVersion
=
KOTLIN_1_4
),
NonStrictOnlyInputTypesChecks
(
sinceVersion
=
KOTLIN_1_4
),
SuspendConversion
(
sinceVersion
=
KOTLIN_1_4
,
defaultState
=
State
.
DISABLED
),
SuspendConversion
(
sinceVersion
=
KOTLIN_1_4
,
defaultState
=
State
.
DISABLED
),
UnitConversion
(
sinceVersion
=
KOTLIN_1_4
,
defaultState
=
State
.
DISABLED
),
OverloadResolutionByLambdaReturnType
(
sinceVersion
=
KOTLIN_1_4
),
OverloadResolutionByLambdaReturnType
(
sinceVersion
=
KOTLIN_1_4
),
BooleanElvisBoundSmartCasts
(
sinceVersion
=
KOTLIN_1_3
,
defaultState
=
State
.
DISABLED
),
// see KT-26357 for details
BooleanElvisBoundSmartCasts
(
sinceVersion
=
KOTLIN_1_3
,
defaultState
=
State
.
DISABLED
),
// see KT-26357 for details
...
...
core/descriptors/src/org/jetbrains/kotlin/builtins/functionTypes.kt
浏览文件 @
71cbe976
...
@@ -54,6 +54,9 @@ val KotlinType.isSuspendFunctionTypeOrSubtype: Boolean
...
@@ -54,6 +54,9 @@ val KotlinType.isSuspendFunctionTypeOrSubtype: Boolean
val
KotlinType
.
isBuiltinFunctionalTypeOrSubtype
:
Boolean
val
KotlinType
.
isBuiltinFunctionalTypeOrSubtype
:
Boolean
get
()
=
isTypeOrSubtypeOf
{
it
.
isBuiltinFunctionalType
}
get
()
=
isTypeOrSubtypeOf
{
it
.
isBuiltinFunctionalType
}
fun
KotlinType
.
isFunctionTypeOrSubtype
(
predicate
:
(
KotlinType
)
->
Boolean
):
Boolean
=
isTypeOrSubtypeOf
{
it
.
isFunctionType
&&
predicate
(
it
)
}
val
KotlinType
.
isFunctionType
:
Boolean
val
KotlinType
.
isFunctionType
:
Boolean
get
()
=
constructor
.
declarationDescriptor
?.
getFunctionalClassKind
()
==
FunctionClassDescriptor
.
Kind
.
Function
get
()
=
constructor
.
declarationDescriptor
?.
getFunctionalClassKind
()
==
FunctionClassDescriptor
.
Kind
.
Function
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录