Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
a3f131d6
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,发现更多精彩内容 >>
提交
a3f131d6
编写于
8月 22, 2016
作者:
S
shiraji
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
KT-13521 Warning right part of "expression ?: null" is useless
#KT-13521 Fixed
上级
a683c2b6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
47 addition
and
0 deletion
+47
-0
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
...frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
+2
-0
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java
...ns/kotlin/diagnostics/rendering/DefaultErrorMessages.java
+1
-0
compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java
...otlin/types/expressions/BasicExpressionTypingVisitor.java
+3
-0
compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.kt
...tformTypes/nullabilityWarnings/uselessElvisRightIsNull.kt
+20
-0
compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.txt
...formTypes/nullabilityWarnings/uselessElvisRightIsNull.txt
+14
-0
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
...g/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
+6
-0
idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt
...c/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt
+1
-0
未找到文件。
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
浏览文件 @
a3f131d6
...
...
@@ -686,6 +686,8 @@ public interface Errors {
DiagnosticFactory1
<
KtBinaryExpression
,
KotlinType
>
USELESS_ELVIS
=
DiagnosticFactory1
.
create
(
WARNING
,
PositioningStrategies
.
USELESS_ELVIS
);
DiagnosticFactory0
<
PsiElement
>
USELESS_ELVIS_ON_LAMBDA_EXPRESSION
=
DiagnosticFactory0
.
create
(
WARNING
);
DiagnosticFactory0
<
KtBinaryExpression
>
USELESS_ELVIS_RIGHT_IS_NULL
=
DiagnosticFactory0
.
create
(
WARNING
,
PositioningStrategies
.
USELESS_ELVIS
);
// Compile-time values
...
...
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java
浏览文件 @
a3f131d6
...
...
@@ -418,6 +418,7 @@ public class DefaultErrorMessages {
MAP
.
put
(
DYNAMIC_UPPER_BOUND
,
"Dynamic type can not be used as an upper bound"
);
MAP
.
put
(
USELESS_ELVIS
,
"Elvis operator (?:) always returns the left operand of non-nullable type {0}"
,
RENDER_TYPE
);
MAP
.
put
(
USELESS_ELVIS_ON_LAMBDA_EXPRESSION
,
"Left operand of elvis operator (?:) is a lambda expression"
);
MAP
.
put
(
USELESS_ELVIS_RIGHT_IS_NULL
,
"Right operand of elvis operator (?:) is useless if it is null"
);
MAP
.
put
(
CONFLICTING_UPPER_BOUNDS
,
"Upper bounds of {0} have empty intersection"
,
NAME
);
MAP
.
put
(
UNSUPPORTED_TYPEALIAS
,
"Type aliases are unsupported (min Kotlin language level: 1.1)"
);
...
...
compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java
浏览文件 @
a3f131d6
...
...
@@ -1198,6 +1198,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
assert
rightTypeInfo
!=
null
:
"Right expression was not processed: "
+
expression
;
boolean
loopBreakContinuePossible
=
leftTypeInfo
.
getJumpOutPossible
()
||
rightTypeInfo
.
getJumpOutPossible
();
KotlinType
rightType
=
rightTypeInfo
.
getType
();
if
(
rightType
!=
null
&&
KtPsiUtil
.
isNullConstant
(
right
))
{
context
.
trace
.
report
(
USELESS_ELVIS_RIGHT_IS_NULL
.
on
(
expression
));
}
// Only left argument DFA is taken into account here: we cannot be sure that right argument is joined
// (we merge it with right DFA if right argument contains no jump outside)
...
...
compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.kt
0 → 100644
浏览文件 @
a3f131d6
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: J.java
import
org.jetbrains.annotations.*;
public
class
J
{
@Nullable
public
static
J
staticN
;
}
// FILE: k.kt
fun
test
()
{
val
a
=
J
.
staticN
<!
USELESS_ELVIS_RIGHT_IS_NULL
!>
?:
null
<!>
foo
(
a
)
}
fun
foo
(
a
:
Any
?)
{
}
compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.txt
0 → 100644
浏览文件 @
a3f131d6
package
public fun foo(/*0*/ a: kotlin.Any?): kotlin.Unit
public fun test(): kotlin.Unit
public open class J {
public constructor J()
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
// Static members
@org.jetbrains.annotations.Nullable() public final var staticN: J?
}
compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java
浏览文件 @
a3f131d6
...
...
@@ -13855,6 +13855,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisInCall.kt");
doTest(fileName);
}
@TestMetadata("uselessElvisRightIsNull.kt")
public void testUselessElvisRightIsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/uselessElvisRightIsNull.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/platformTypes/rawTypes")
idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt
浏览文件 @
a3f131d6
...
...
@@ -98,6 +98,7 @@ class QuickFixRegistrar : QuickFixContributor {
WRONG_GETTER_RETURN_TYPE
.
registerFactory
(
ChangeAccessorTypeFix
)
USELESS_ELVIS
.
registerFactory
(
RemoveUselessElvisFix
)
USELESS_ELVIS_RIGHT_IS_NULL
.
registerFactory
(
RemoveUselessElvisFix
)
val
removeRedundantModifierFactory
=
RemoveModifierFix
.
createRemoveModifierFactory
(
true
)
REDUNDANT_MODIFIER
.
registerFactory
(
removeRedundantModifierFactory
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录