Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
22874357
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,发现更多精彩内容 >>
提交
22874357
编写于
6月 01, 2020
作者:
S
simon.ogorodnik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIR] KT-39033: Fix generic property override detection
#KT-39033 Fixed
上级
e4a1c8dc
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
86 addition
and
17 deletion
+86
-17
compiler/fir/analysis-tests/testData/resolve/genericReceiverPropertyOverride.kt
...tests/testData/resolve/genericReceiverPropertyOverride.kt
+15
-0
compiler/fir/analysis-tests/testData/resolve/genericReceiverPropertyOverride.txt
...ests/testData/resolve/genericReceiverPropertyOverride.txt
+39
-0
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java
...org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java
+5
-0
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java
.../kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java
+5
-0
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt
...ains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt
+17
-8
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt
...ains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt
+5
-9
未找到文件。
compiler/fir/analysis-tests/testData/resolve/genericReceiverPropertyOverride.kt
0 → 100644
浏览文件 @
22874357
abstract
class
A
{
open
val
<
D
>
Inv
<
D
>.
phasedFir
:
D
get
()
=
TODO
()
}
abstract
class
B
:
A
()
{
final
override
val
<
D
>
Inv
<
D
>.
phasedFir
:
D
get
()
=
TODO
()
}
abstract
class
Inv
<
E
>
class
C
:
B
()
{
fun
foo
(
x
:
Inv
<
String
>)
{
x
.
phasedFir
}
}
\ No newline at end of file
compiler/fir/analysis-tests/testData/resolve/genericReceiverPropertyOverride.txt
0 → 100644
浏览文件 @
22874357
FILE: genericReceiverPropertyOverride.kt
public abstract class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public open val <D> R|Inv<D>|.phasedFir: R|D|
public get(): R|D| {
^ R|kotlin/TODO|()
}
}
public abstract class B : R|A| {
public constructor(): R|B| {
super<R|A|>()
}
public final override val <D> R|Inv<D>|.phasedFir: R|D|
public get(): R|D| {
^ R|kotlin/TODO|()
}
}
public abstract class Inv<E> : R|kotlin/Any| {
public constructor<E>(): R|Inv<E>| {
super<R|kotlin/Any|>()
}
}
public final class C : R|B| {
public constructor(): R|C| {
super<R|B|>()
}
public final fun foo(x: R|Inv<kotlin/String>|): R|kotlin/Unit| {
(this@R|/C|, R|<local>/x|).R|/B.phasedFir|<R|kotlin/String|>
}
}
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java
浏览文件 @
22874357
...
...
@@ -193,6 +193,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest
(
"compiler/fir/analysis-tests/testData/resolve/genericFunctions.kt"
);
}
@TestMetadata
(
"genericReceiverPropertyOverride.kt"
)
public
void
testGenericReceiverPropertyOverride
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/genericReceiverPropertyOverride.kt"
);
}
@TestMetadata
(
"incorrectSuperCall.kt"
)
public
void
testIncorrectSuperCall
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/incorrectSuperCall.kt"
);
...
...
compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java
浏览文件 @
22874357
...
...
@@ -193,6 +193,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest
(
"compiler/fir/analysis-tests/testData/resolve/genericFunctions.kt"
);
}
@TestMetadata
(
"genericReceiverPropertyOverride.kt"
)
public
void
testGenericReceiverPropertyOverride
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/genericReceiverPropertyOverride.kt"
);
}
@TestMetadata
(
"incorrectSuperCall.kt"
)
public
void
testIncorrectSuperCall
()
throws
Exception
{
runTest
(
"compiler/fir/analysis-tests/testData/resolve/incorrectSuperCall.kt"
);
...
...
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirAbstractOverrideChecker.kt
浏览文件 @
22874357
...
...
@@ -5,8 +5,7 @@
package
org.jetbrains.kotlin.fir.scopes.impl
import
org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
import
org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import
org.jetbrains.kotlin.fir.declarations.*
import
org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import
org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
import
org.jetbrains.kotlin.fir.scopes.FirOverrideChecker
...
...
@@ -17,15 +16,24 @@ abstract class FirAbstractOverrideChecker : FirOverrideChecker {
protected
abstract
fun
isEqualTypes
(
candidateTypeRef
:
FirTypeRef
,
baseTypeRef
:
FirTypeRef
,
substitutor
:
ConeSubstitutor
):
Boolean
private
fun
isCompatibleTypeParameters
(
overrideCandidate
:
FirTypeParameterRef
,
baseDeclaration
:
FirTypeParameterRef
,
substitutor
:
ConeSubstitutor
):
Boolean
{
if
(
overrideCandidate
.
symbol
==
baseDeclaration
.
symbol
)
return
true
if
(
overrideCandidate
!
is
FirTypeParameter
||
baseDeclaration
!
is
FirTypeParameter
)
return
false
return
overrideCandidate
.
bounds
.
zip
(
baseDeclaration
.
bounds
).
all
{
(
aBound
,
bBound
)
->
isEqualTypes
(
aBound
,
bBound
,
substitutor
)
}
}
protected
fun
getSubstitutorIfTypeParametersAreCompatible
(
overrideCandidate
:
Fir
SimpleFunction
,
baseDeclaration
:
Fir
SimpleFunction
overrideCandidate
:
Fir
CallableMemberDeclaration
<
*
>
,
baseDeclaration
:
Fir
CallableMemberDeclaration
<
*
>
):
ConeSubstitutor
?
{
val
substitutor
=
buildSubstitutorForOverridesCheck
(
overrideCandidate
,
baseDeclaration
)
?:
return
null
if
(!
overrideCandidate
.
typeParameters
.
zip
(
baseDeclaration
.
typeParameters
).
all
{
(
a
,
b
)
->
a
.
bounds
.
size
==
b
.
bounds
.
size
&&
a
.
bounds
.
zip
(
b
.
bounds
).
all
{
(
aBound
,
bBound
)
->
isEqualTypes
(
aBound
,
bBound
,
substitutor
)
}
if
(
overrideCandidate
.
typeParameters
.
zip
(
baseDeclaration
.
typeParameters
).
any
{
(
override
,
base
)
->
!
isCompatibleTypeParameters
(
override
,
base
,
substitutor
)
}
)
return
null
return
substitutor
...
...
@@ -38,6 +46,7 @@ fun buildSubstitutorForOverridesCheck(
):
ConeSubstitutor
?
{
if
(
overrideCandidate
.
typeParameters
.
size
!=
baseDeclaration
.
typeParameters
.
size
)
return
null
if
(
baseDeclaration
.
typeParameters
.
isEmpty
())
return
ConeSubstitutor
.
Empty
val
types
=
baseDeclaration
.
typeParameters
.
map
{
ConeTypeParameterTypeImpl
(
it
.
symbol
.
toLookupTag
(),
false
)
}
...
...
compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt
浏览文件 @
22874357
...
...
@@ -11,11 +11,7 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
import
org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
import
org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import
org.jetbrains.kotlin.fir.typeContext
import
org.jetbrains.kotlin.fir.types.ConeKotlinType
import
org.jetbrains.kotlin.fir.types.ConeTypeContext
import
org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import
org.jetbrains.kotlin.fir.types.FirTypeRef
import
org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker.strictEqualTypes
import
org.jetbrains.kotlin.fir.types.*
import
org.jetbrains.kotlin.types.AbstractTypeChecker
import
org.jetbrains.kotlin.types.model.KotlinTypeMarker
import
org.jetbrains.kotlin.types.model.SimpleTypeMarker
...
...
@@ -24,7 +20,7 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
private
val
context
:
ConeTypeContext
=
session
.
typeContext
private
fun
isEqualTypes
(
candidateType
:
ConeKotlinType
,
baseType
:
ConeKotlinType
,
substitutor
:
ConeSubstitutor
):
Boolean
{
private
fun
isEqualTypes
(
candidateType
:
ConeKotlinType
,
baseType
:
ConeKotlinType
,
substitutor
:
ConeSubstitutor
):
Boolean
{
val
substitutedCandidateType
=
substitutor
.
substituteOrSelf
(
candidateType
)
val
substitutedBaseType
=
substitutor
.
substituteOrSelf
(
baseType
)
return
with
(
context
)
{
...
...
@@ -76,8 +72,8 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
overrideCandidate
:
FirCallableMemberDeclaration
<
*
>,
baseDeclaration
:
FirProperty
):
Boolean
{
// TODO: substitutor
return
overrideCandidate
is
FirProperty
&&
isEqualReceiverTypes
(
overrideCandidate
.
receiverTypeRef
,
baseDeclaration
.
receiverTypeRef
,
ConeSubstitutor
.
Empty
)
if
(
overrideCandidate
!
is
FirProperty
)
return
false
val
substitutor
=
getSubstitutorIfTypeParametersAreCompatible
(
overrideCandidate
,
baseDeclaration
)
?:
return
false
return
isEqualReceiverTypes
(
overrideCandidate
.
receiverTypeRef
,
baseDeclaration
.
receiverTypeRef
,
substitutor
)
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录