Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
266432a4
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,发现更多精彩内容 >>
提交
266432a4
编写于
2月 03, 2021
作者:
J
Jinseong Jeon
提交者:
Dmitriy Novozhilov
2月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIR checker: fix condition for property type mismatch on override
上级
065d0c66
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
21 addition
and
21 deletion
+21
-21
compiler/fir/analysis-tests/testData/resolve/diagnostics/propertyTypeMismatchOnOverride.kt
...ata/resolve/diagnostics/propertyTypeMismatchOnOverride.kt
+2
-2
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt
...n/fir/analysis/checkers/declaration/FirOverrideChecker.kt
+16
-8
compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt
compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt
+0
-9
compiler/testData/diagnostics/tests/subtyping/kt3159.kt
compiler/testData/diagnostics/tests/subtyping/kt3159.kt
+1
-0
compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.3.fir.kt
...ion/class-declaration/abstract-classes/p-2/neg/1.3.fir.kt
+2
-2
未找到文件。
compiler/fir/analysis-tests/testData/resolve/diagnostics/propertyTypeMismatchOnOverride.kt
浏览文件 @
266432a4
...
@@ -3,7 +3,7 @@ open class A {
...
@@ -3,7 +3,7 @@ open class A {
}
}
open
class
B
:
A
{
open
class
B
:
A
{
override
var
test
:
Double
=
20.0
override
var
test
:
<!
VAR_TYPE_MISMATCH_ON_OVERRIDE
!>
Double
<
!
>
=
20.0
}
}
class
C
()
:
A
()
{
class
C
()
:
A
()
{
...
@@ -15,7 +15,7 @@ open class D() : B() {
...
@@ -15,7 +15,7 @@ open class D() : B() {
}
}
class
E
<
T
:
Double
>(
val
value
:
T
)
:
B
()
{
class
E
<
T
:
Double
>(
val
value
:
T
)
:
B
()
{
override
var
test
:
T
=
value
override
var
test
:
<!
VAR_TYPE_MISMATCH_ON_OVERRIDE
!>
T
<
!
>
=
value
}
}
open
class
F
<
T
:
Number
>(
val
value
:
T
)
{
open
class
F
<
T
:
Number
>(
val
value
:
T
)
{
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirOverrideChecker.kt
浏览文件 @
266432a4
...
@@ -61,13 +61,13 @@ object FirOverrideChecker : FirRegularClassChecker() {
...
@@ -61,13 +61,13 @@ object FirOverrideChecker : FirRegularClassChecker() {
private
fun
ConeKotlinType
.
substituteAllTypeParameters
(
private
fun
ConeKotlinType
.
substituteAllTypeParameters
(
overrideDeclaration
:
FirCallableMemberDeclaration
<
*
>,
overrideDeclaration
:
FirCallableMemberDeclaration
<
*
>,
baseDeclaration
Symbol
:
FirCallableSymbol
<
*
>,
baseDeclaration
:
FirCallableDeclaration
<
*
>,
):
ConeKotlinType
{
):
ConeKotlinType
{
if
(
overrideDeclaration
.
typeParameters
.
isEmpty
())
{
if
(
overrideDeclaration
.
typeParameters
.
isEmpty
())
{
return
this
return
this
}
}
val
parametersOwner
=
baseDeclaration
Symbol
.
fir
.
safeAs
<
FirTypeParametersOwner
>()
val
parametersOwner
=
baseDeclaration
.
safeAs
<
FirTypeParametersOwner
>()
?:
return
this
?:
return
this
val
map
=
mutableMapOf
<
FirTypeParameterSymbol
,
ConeKotlinType
>()
val
map
=
mutableMapOf
<
FirTypeParameterSymbol
,
ConeKotlinType
>()
...
@@ -130,27 +130,35 @@ object FirOverrideChecker : FirRegularClassChecker() {
...
@@ -130,27 +130,35 @@ object FirOverrideChecker : FirRegularClassChecker() {
}
}
}
}
// See [OverrideResolver#isReturnTypeOkForOverride]
private
fun
FirCallableMemberDeclaration
<*>.
checkReturnType
(
private
fun
FirCallableMemberDeclaration
<*>.
checkReturnType
(
overriddenSymbols
:
List
<
FirCallableSymbol
<
*
>>,
overriddenSymbols
:
List
<
FirCallableSymbol
<
*
>>,
typeCheckerContext
:
AbstractTypeCheckerContext
,
typeCheckerContext
:
AbstractTypeCheckerContext
,
context
:
CheckerContext
,
context
:
CheckerContext
,
):
FirMemberDeclaration
?
{
):
FirMemberDeclaration
?
{
val
r
eturnType
=
returnTypeRef
.
safeAs
<
FirResolvedTypeRef
>()
?.
type
val
overridingR
eturnType
=
returnTypeRef
.
safeAs
<
FirResolvedTypeRef
>()
?.
type
?:
return
null
?:
return
null
// Don't report *_ON_OVERRIDE diagnostics according to an error return type. That should be reported separately.
// Don't report *_ON_OVERRIDE diagnostics according to an error return type. That should be reported separately.
if
(
r
eturnType
is
ConeKotlinErrorType
)
{
if
(
overridingR
eturnType
is
ConeKotlinErrorType
)
{
return
null
return
null
}
}
val
bounds
=
overriddenSymbols
.
map
{
context
.
returnTypeCalculator
.
tryCalculateReturnType
(
it
.
fir
).
coneType
.
upperBoundIfFlexible
()
}
val
bounds
=
overriddenSymbols
.
map
{
context
.
returnTypeCalculator
.
tryCalculateReturnType
(
it
.
fir
).
coneType
.
upperBoundIfFlexible
()
}
for
(
it
in
bounds
.
indices
)
{
for
(
it
in
bounds
.
indices
)
{
val
restriction
=
bounds
[
it
]
val
overriddenDeclaration
=
overriddenSymbols
[
it
].
fir
.
substituteAllTypeParameters
(
this
,
overriddenSymbols
[
it
])
if
(!
AbstractTypeChecker
.
isSubtypeOf
(
typeCheckerContext
,
returnType
,
restriction
))
{
val
overriddenReturnType
=
bounds
[
it
].
substituteAllTypeParameters
(
this
,
overriddenDeclaration
)
return
overriddenSymbols
[
it
].
fir
.
safeAs
()
val
isReturnTypeOkForOverride
=
if
(
overriddenDeclaration
is
FirProperty
&&
overriddenDeclaration
.
isVar
)
AbstractTypeChecker
.
equalTypes
(
typeCheckerContext
,
overridingReturnType
,
overriddenReturnType
)
else
AbstractTypeChecker
.
isSubtypeOf
(
typeCheckerContext
,
overridingReturnType
,
overriddenReturnType
)
if
(!
isReturnTypeOkForOverride
)
{
return
overriddenDeclaration
.
safeAs
()
}
}
}
}
...
...
compiler/testData/diagnostics/tests/subtyping/kt3159.fir.kt
已删除
100644 → 0
浏览文件 @
065d0c66
interface
Super
{
var
v
:
CharSequence
val
v2
:
CharSequence
}
class
Sub
:
Super
{
override
var
v
:
String
=
"fail"
override
val
v2
:
String
=
"ok"
}
\ No newline at end of file
compiler/testData/diagnostics/tests/subtyping/kt3159.kt
浏览文件 @
266432a4
// FIR_IDENTICAL
interface
Super
{
interface
Super
{
var
v
:
CharSequence
var
v
:
CharSequence
val
v2
:
CharSequence
val
v2
:
CharSequence
...
...
compiler/tests-spec/testData/diagnostics/linked/declarations/classifier-declaration/class-declaration/abstract-classes/p-2/neg/1.3.fir.kt
浏览文件 @
266432a4
...
@@ -18,7 +18,7 @@ class Case1 : Base() {
...
@@ -18,7 +18,7 @@ class Case1 : Base() {
override
val
a
:
<!
PROPERTY_TYPE_MISMATCH_ON_OVERRIDE
!>
Any
?<!>
override
val
a
:
<!
PROPERTY_TYPE_MISMATCH_ON_OVERRIDE
!>
Any
?<!>
get
()
=
TODO
()
get
()
=
TODO
()
override
var
b
:
String
override
var
b
:
<!
VAR_TYPE_MISMATCH_ON_OVERRIDE
!>
String
<
!
>
get
()
=
TODO
()
get
()
=
TODO
()
set
(
value
)
set
(
value
)
{}
{}
...
@@ -29,7 +29,7 @@ class Case1 : Base() {
...
@@ -29,7 +29,7 @@ class Case1 : Base() {
* TESTCASE NUMBER: 2
* TESTCASE NUMBER: 2
*/
*/
class
Case2
(
override
val
a
:
String
,
override
var
b
:
String
)
:
Base
()
{
class
Case2
(
override
val
a
:
String
,
override
var
b
:
<!
VAR_TYPE_MISMATCH_ON_OVERRIDE
!>
String
<
!
>
)
:
Base
()
{
override
fun
foo
():
<!
RETURN_TYPE_MISMATCH_ON_OVERRIDE
!>
CharSequence
?<!>
{
override
fun
foo
():
<!
RETURN_TYPE_MISMATCH_ON_OVERRIDE
!>
CharSequence
?<!>
{
return
""
return
""
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录