Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
9ad88a5a
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,发现更多精彩内容 >>
提交
9ad88a5a
编写于
1月 31, 2021
作者:
E
eugenpolytechnic
提交者:
Mikhail Glukhikh
2月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIR: introduce parameter type is Throwable check
上级
5c0231b7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
67 addition
and
16 deletion
+67
-16
compiler/fir/analysis-tests/testData/resolve/catchParameter.fir.txt
...ir/analysis-tests/testData/resolve/catchParameter.fir.txt
+23
-2
compiler/fir/analysis-tests/testData/resolve/catchParameter.kt
...ler/fir/analysis-tests/testData/resolve/catchParameter.kt
+13
-3
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt
.../org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt
+5
-4
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCatchParameterChecker.kt
.../analysis/checkers/expression/FirCatchParameterChecker.kt
+24
-5
compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt
...rolFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt
+2
-2
未找到文件。
compiler/fir/analysis-tests/testData/resolve/catchParameter.fir.txt
浏览文件 @
9ad88a5a
FILE: catchParameter.kt
public final fun <T> test(): R|kotlin/Unit| {
public final typealias StringType = R|kotlin/String|
public final fun <T : R|kotlin/Throwable|> test(): R|kotlin/Unit| {
try {
}
catch (e: R|kotlin/NullPointerException| = R|java/lang/NullPointerException.NullPointerException|()) {
...
...
@@ -10,6 +11,26 @@ FILE: catchParameter.kt
catch (e: R|T|) {
}
try {
}
catch (e: R|() -> kotlin/Int|) {
}
try {
}
catch (e: R|StringType|) {
}
try {
}
catch (e: R|kotlin/Int| = Int(5)) {
}
try {
}
catch (e: R|kotlin/Throwable|) {
}
}
public final inline fun <reified T> anotherTest(): R|kotlin/Unit| {
try {
...
...
@@ -17,4 +38,4 @@ FILE: catchParameter.kt
catch (e: R|T|) {
}
}
\ No newline at end of file
}
compiler/fir/analysis-tests/testData/resolve/catchParameter.kt
浏览文件 @
9ad88a5a
fun
<
T
>
test
()
{
typealias
StringType
=
String
fun
<
T
:
Throwable
>
test
()
{
try
{
}
catch
(<!
CATCH_PARAMETER_WITH_DEFAULT_VALUE
!>
e
:
NullPointerException
=
NullPointerException
()<!>)
{
...
...
@@ -6,8 +8,16 @@ fun <T> test() {
}
try
{}
catch
(<!
TYPE_PARAMETER_IN_CATCH_CLAUSE
!>
e
:
T
<
!
>)
{}
try
{}
catch
(<!
TYPE_MISMATCH
!>
e
:
()
->
Int
<
!
>)
{}
try
{}
catch
(<!
TYPE_MISMATCH
!>
e
:
StringType
<
!
>)
{}
try
{}
catch
(<!
CATCH_PARAMETER_WITH_DEFAULT_VALUE
,
TYPE_MISMATCH
!>
e
:
Int
=
5
<!>)
{}
try
{}
catch
(
e
:
Throwable
)
{}
}
inline
fun
<
reified
T
>
anotherTest
()
{
try
{}
catch
(<!
REIFIED_TYPE_IN_CATCH_CLAUSE
!>
e
:
T
<
!
>)
{}
}
\ No newline at end of file
try
{}
catch
(<!
REIFIED_TYPE_IN_CATCH_CLAUSE
,
TYPE_MISMATCH
!>
e
:
T
<
!
>)
{}
}
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt
浏览文件 @
9ad88a5a
...
...
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
import
org.jetbrains.kotlin.descriptors.Visibility
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.FirSymbolOwner
import
org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer.isSupertypeOf
import
org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import
org.jetbrains.kotlin.fir.analysis.diagnostics.modalityModifier
import
org.jetbrains.kotlin.fir.analysis.diagnostics.overrideModifier
...
...
@@ -22,18 +23,18 @@ import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import
org.jetbrains.kotlin.fir.expressions.impl.FirEmptyExpressionBlock
import
org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import
org.jetbrains.kotlin.fir.resolve.firSymbolProvider
import
org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import
org.jetbrains.kotlin.fir.resolve.toSymbol
import
org.jetbrains.kotlin.fir.resolve.transformers.firClassLike
import
org.jetbrains.kotlin.fir.scopes.ProcessorAction
import
org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions
import
org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import
org.jetbrains.kotlin.fir.symbols.StandardClassIds
import
org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import
org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import
org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import
org.jetbrains.kotlin.fir.types.ConeClassLikeType
import
org.jetbrains.kotlin.fir.types.ConeKotlinType
import
org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import
org.jetbrains.kotlin.fir.types.FirTypeRef
import
org.jetbrains.kotlin.fir.typeCheckerContext
import
org.jetbrains.kotlin.fir.types.*
import
org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import
org.jetbrains.kotlin.lexer.KtTokens
import
org.jetbrains.kotlin.psi.KtModifierList
...
...
compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirCatchParameterChecker.kt
浏览文件 @
9ad88a5a
...
...
@@ -5,31 +5,50 @@
package
org.jetbrains.kotlin.fir.analysis.checkers.expression
import
org.jetbrains.kotlin.fir.FirSession
import
org.jetbrains.kotlin.fir.analysis.cfa.FirReturnsImpliesAnalyzer.isSupertypeOf
import
org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import
org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import
org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import
org.jetbrains.kotlin.fir.expressions.FirTryExpression
import
org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import
org.jetbrains.kotlin.fir.symbols.StandardClassIds
import
org.jetbrains.kotlin.fir.typeCheckerContext
import
org.jetbrains.kotlin.fir.types.ConeKotlinType
import
org.jetbrains.kotlin.fir.types.ConeTypeParameterType
import
org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import
org.jetbrains.kotlin.fir.types.constructClassLikeType
object
FirCatchParameterChecker
:
FirTryExpressionChecker
()
{
private
val
throwable
=
StandardClassIds
.
byName
(
"Throwable"
)
.
constructClassLikeType
(
emptyArray
(),
false
)
override
fun
check
(
expression
:
FirTryExpression
,
context
:
CheckerContext
,
reporter
:
DiagnosticReporter
)
{
for
(
catchEntry
in
expression
.
catches
)
{
val
catchParameter
=
catchEntry
.
parameter
if
(
catchParameter
.
defaultValue
!=
null
)
reporter
.
report
(
catchParameter
.
source
?.
let
{
FirErrors
.
CATCH_PARAMETER_WITH_DEFAULT_VALUE
.
on
(
it
)
})
catchParameter
.
source
?.
let
{
reporter
.
report
(
FirErrors
.
CATCH_PARAMETER_WITH_DEFAULT_VALUE
.
on
(
it
))
}
val
typeRef
=
catchParameter
.
returnTypeRef
if
(
typeRef
is
FirResolvedTypeRef
&&
typeRef
.
type
is
ConeTypeParameterType
)
{
val
isReified
=
(
typeRef
.
type
as
ConeTypeParameterType
).
lookupTag
.
typeParameterSymbol
.
fir
.
isReified
if
(
typeRef
!
is
FirResolvedTypeRef
)
return
val
coneType
=
typeRef
.
type
if
(
coneType
is
ConeTypeParameterType
)
{
val
isReified
=
coneType
.
lookupTag
.
typeParameterSymbol
.
fir
.
isReified
if
(
isReified
)
{
reporter
.
report
(
catchParameter
.
source
?.
let
{
FirErrors
.
REIFIED_TYPE_IN_CATCH_CLAUSE
.
on
(
it
)
})
catchParameter
.
source
?.
let
{
reporter
.
report
(
FirErrors
.
REIFIED_TYPE_IN_CATCH_CLAUSE
.
on
(
it
))
}
}
else
{
reporter
.
report
(
catchParameter
.
source
?.
let
{
FirErrors
.
TYPE_PARAMETER_IN_CATCH_CLAUSE
.
on
(
it
)
})
catchParameter
.
source
?.
let
{
reporter
.
report
(
FirErrors
.
TYPE_PARAMETER_IN_CATCH_CLAUSE
.
on
(
it
))
}
}
}
if
(!
coneType
.
isThrowable
(
context
.
session
))
catchParameter
.
source
?.
let
{
reporter
.
report
(
FirErrors
.
TYPE_MISMATCH
.
on
(
it
,
throwable
,
coneType
))
}
}
}
private
fun
ConeKotlinType
.
isThrowable
(
session
:
FirSession
)
=
throwable
.
isSupertypeOf
(
session
.
typeCheckerContext
,
this
.
fullyExpandedType
(
session
))
}
\ No newline at end of file
compiler/testData/diagnostics/tests/controlFlowAnalysis/deadCode/deadCodeDifferentExamples.fir.kt
浏览文件 @
9ad88a5a
...
...
@@ -109,7 +109,7 @@ fun t7() : Int {
return
1
2
}
catch
(
e
:
Any
)
{
catch
(
<!
TYPE_MISMATCH
!>
e
:
Any
<
!
>
)
{
2
}
return
1
// this is OK, like in Java
...
...
@@ -120,7 +120,7 @@ fun t8() : Int {
return
1
2
}
catch
(
e
:
Any
)
{
catch
(
<!
TYPE_MISMATCH
!>
e
:
Any
<
!
>
)
{
return
1
2
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录