Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
7c61ddc7
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,发现更多精彩内容 >>
提交
7c61ddc7
编写于
2月 11, 2021
作者:
D
Dmitriy Novozhilov
提交者:
TeamCityServer
2月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FE] Allow declaring protected constructors in sealed classes
#KT-44865 Fixed
上级
f3a8fcae
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
447 addition
and
8 deletion
+447
-8
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java
.../test/runners/FirOldFrontendDiagnosticsTestGenerated.java
+12
-0
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
...frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
+1
-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/resolve/DeclarationsChecker.kt
...d/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt
+16
-6
compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.kt
...estData/diagnostics/tests/sealed/NonPrivateConstructor.kt
+2
-2
compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.fir.kt
...ostics/tests/sealed/protectedConstructors_disabled.fir.kt
+41
-0
compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.kt
...iagnostics/tests/sealed/protectedConstructors_disabled.kt
+41
-0
compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.txt
...agnostics/tests/sealed/protectedConstructors_disabled.txt
+119
-0
compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.fir.kt
...nostics/tests/sealed/protectedConstructors_enabled.fir.kt
+41
-0
compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.kt
...diagnostics/tests/sealed/protectedConstructors_enabled.kt
+41
-0
compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.txt
...iagnostics/tests/sealed/protectedConstructors_enabled.txt
+119
-0
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
...etbrains/kotlin/test/runners/DiagnosticTestGenerated.java
+12
-0
idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt
...c/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt
+1
-0
未找到文件。
compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java
浏览文件 @
7c61ddc7
...
@@ -24511,6 +24511,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
...
@@ -24511,6 +24511,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/sealed/OperationWhen.kt");
runTest("compiler/testData/diagnostics/tests/sealed/OperationWhen.kt");
}
}
@Test
@TestMetadata("protectedConstructors_disabled.kt")
public void testProtectedConstructors_disabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.kt");
}
@Test
@TestMetadata("protectedConstructors_enabled.kt")
public void testProtectedConstructors_enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.kt");
}
@Test
@Test
@TestMetadata("RedundantAbstract.kt")
@TestMetadata("RedundantAbstract.kt")
public void testRedundantAbstract() throws Exception {
public void testRedundantAbstract() throws Exception {
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java
浏览文件 @
7c61ddc7
...
@@ -346,6 +346,7 @@ public interface Errors {
...
@@ -346,6 +346,7 @@ public interface Errors {
DiagnosticFactory0
<
PsiElement
>
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
=
DiagnosticFactory0
.
create
(
ERROR
);
DiagnosticFactory0
<
PsiElement
>
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
=
DiagnosticFactory0
.
create
(
ERROR
);
DiagnosticFactory0
<
PsiElement
>
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
=
DiagnosticFactory0
.
create
(
ERROR
);
DiagnosticFactory0
<
PsiElement
>
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
=
DiagnosticFactory0
.
create
(
ERROR
);
DiagnosticFactory0
<
PsiElement
>
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
=
DiagnosticFactory0
.
create
(
ERROR
);
// Inline and value classes
// Inline and value classes
...
...
compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java
浏览文件 @
7c61ddc7
...
@@ -705,6 +705,7 @@ public class DefaultErrorMessages {
...
@@ -705,6 +705,7 @@ public class DefaultErrorMessages {
MAP
.
put
(
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
,
"Constructor must be private in enum class"
);
MAP
.
put
(
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
,
"Constructor must be private in enum class"
);
MAP
.
put
(
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
,
"Constructor must be private in sealed class"
);
MAP
.
put
(
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
,
"Constructor must be private in sealed class"
);
MAP
.
put
(
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
,
"Constructor must be private or protected in sealed class"
);
MAP
.
put
(
INLINE_CLASS_NOT_TOP_LEVEL
,
"Inline classes cannot be local or inner"
);
MAP
.
put
(
INLINE_CLASS_NOT_TOP_LEVEL
,
"Inline classes cannot be local or inner"
);
MAP
.
put
(
INLINE_CLASS_NOT_FINAL
,
"Inline classes can be only final"
);
MAP
.
put
(
INLINE_CLASS_NOT_FINAL
,
"Inline classes can be only final"
);
...
...
compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt
浏览文件 @
7c61ddc7
...
@@ -289,12 +289,22 @@ class DeclarationsChecker(
...
@@ -289,12 +289,22 @@ class DeclarationsChecker(
private
fun
checkConstructorVisibility
(
constructorDescriptor
:
ClassConstructorDescriptor
,
declaration
:
KtDeclaration
)
{
private
fun
checkConstructorVisibility
(
constructorDescriptor
:
ClassConstructorDescriptor
,
declaration
:
KtDeclaration
)
{
val
visibilityModifier
=
declaration
.
visibilityModifier
()
val
visibilityModifier
=
declaration
.
visibilityModifier
()
if
(
visibilityModifier
!=
null
&&
visibilityModifier
.
node
?.
elementType
!=
KtTokens
.
PRIVATE_KEYWORD
)
{
val
visibilityKeyword
=
visibilityModifier
?.
node
?.
elementType
?:
return
val
classDescriptor
=
constructorDescriptor
.
containingDeclaration
val
classDescriptor
=
constructorDescriptor
.
containingDeclaration
if
(
classDescriptor
.
kind
==
ClassKind
.
ENUM_CLASS
)
{
trace
.
report
(
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
.
on
(
visibilityModifier
))
when
{
}
else
if
(
classDescriptor
.
modality
==
Modality
.
SEALED
)
{
classDescriptor
.
kind
==
ClassKind
.
ENUM_CLASS
->
{
trace
.
report
(
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
.
on
(
visibilityModifier
))
if
(
visibilityKeyword
!=
KtTokens
.
PRIVATE_KEYWORD
)
{
trace
.
report
(
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
.
on
(
visibilityModifier
))
}
}
classDescriptor
.
modality
==
Modality
.
SEALED
->
{
val
protectedIsAllowed
=
languageVersionSettings
.
supportsFeature
(
LanguageFeature
.
AllowSealedInheritorsInDifferentFilesOfSamePackage
)
if
(!(
visibilityKeyword
==
KtTokens
.
PRIVATE_KEYWORD
||
(
protectedIsAllowed
&&
visibilityKeyword
==
KtTokens
.
PROTECTED_KEYWORD
)))
{
val
factory
=
if
(
protectedIsAllowed
)
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
else
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
trace
.
report
(
factory
.
on
(
visibilityModifier
))
}
}
}
}
}
}
}
...
...
compiler/testData/diagnostics/tests/sealed/NonPrivateConstructor.kt
浏览文件 @
7c61ddc7
sealed
class
Sealed
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
val
x
:
Int
)
{
sealed
class
Sealed
protected
constructor
(
val
x
:
Int
)
{
object
FIRST
:
Sealed
()
object
FIRST
:
Sealed
()
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
public
<!>
constructor
():
this
(
42
)
<!
NON_PRIVATE_
OR_PROTECTED_
CONSTRUCTOR_IN_SEALED
!>
public
<!>
constructor
():
this
(
42
)
constructor
(
y
:
Int
,
z
:
Int
):
this
(
y
+
z
)
constructor
(
y
:
Int
,
z
:
Int
):
this
(
y
+
z
)
}
}
compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.fir.kt
0 → 100644
浏览文件 @
7c61ddc7
// LANGUAGE: -AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed
class
Case1
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case1
(
10
)
class
Inheritor2
:
Case1
(
"Hello"
)
}
sealed
class
Case2
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
val
x
:
Int
)<!>
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case2
(
10
)
class
Inheritor2
:
Case2
(
"Hello"
)
}
sealed
class
Case3
private
constructor
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case3
(
10
)
// should OK
class
Inheritor2
:
Case3
(
"Hello"
)
}
class
Case3Inheritor3
:
<!
INAPPLICABLE_CANDIDATE
!>
Case3
<
!
>(
20
)
// should be an error in 1.6 (?)
sealed
class
Case4
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
x
:
Int
)<!>
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case4
(
10
)
class
Inheritor2
:
Case4
(
"Hello"
)
}
sealed
class
Case5
()
{
private
constructor
(
x
:
Int
)
:
this
()
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
x
:
Byte
)
:
this
()<!>
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
internal
constructor
(
x
:
Short
)
:
this
()<!>
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
public
constructor
(
x
:
Long
)
:
this
()<!>
constructor
(
x
:
Double
)
:
this
()
}
compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.kt
0 → 100644
浏览文件 @
7c61ddc7
// LANGUAGE: -AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed
class
Case1
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case1
(
10
)
class
Inheritor2
:
Case1
(
"Hello"
)
}
sealed
class
Case2
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case2
(
10
)
class
Inheritor2
:
Case2
(
"Hello"
)
}
sealed
class
Case3
private
constructor
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case3
(
10
)
// should OK
class
Inheritor2
:
Case3
(
"Hello"
)
}
class
Case3Inheritor3
:
Case3
(
20
)
// should be an error in 1.6 (?)
sealed
class
Case4
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
x
:
Int
)
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case4
(
10
)
class
Inheritor2
:
Case4
(
"Hello"
)
}
sealed
class
Case5
()
{
private
constructor
(
x
:
Int
)
:
this
()
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
<!>
constructor
(
x
:
Byte
)
:
this
()
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
internal
<!>
constructor
(
x
:
Short
)
:
this
()
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
public
<!>
constructor
(
x
:
Long
)
:
this
()
constructor
(
x
:
Double
)
:
this
()
}
compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.txt
0 → 100644
浏览文件 @
7c61ddc7
package
public sealed class Case1 {
private constructor Case1(/*0*/ x: kotlin.Int)
protected constructor Case1(/*0*/ s: kotlin.String)
public final val x: kotlin.Int
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
public final class Inheritor1 : Case1 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public final class Inheritor2 : Case1 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
}
public sealed class Case2 {
protected constructor Case2(/*0*/ x: kotlin.Int)
protected constructor Case2(/*0*/ s: kotlin.String)
public final val x: kotlin.Int
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
public final class Inheritor1 : Case2 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public final class Inheritor2 : Case2 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
}
public sealed class Case3 {
private constructor Case3(/*0*/ x: kotlin.Int)
protected constructor Case3(/*0*/ s: kotlin.String)
public final val x: kotlin.Int
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
public final class Inheritor1 : Case3 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public final class Inheritor2 : Case3 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
}
public final class Case3Inheritor3 : Case3 {
public constructor Case3Inheritor3()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public sealed class Case4 {
protected constructor Case4(/*0*/ x: kotlin.Int)
protected constructor Case4(/*0*/ s: kotlin.String)
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
public final class Inheritor1 : Case4 {
public constructor Inheritor1()
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
}
public final class Inheritor2 : Case4 {
public constructor Inheritor2()
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
}
}
public sealed class Case5 {
private constructor Case5()
protected constructor Case5(/*0*/ x: kotlin.Byte)
private constructor Case5(/*0*/ x: kotlin.Double)
private constructor Case5(/*0*/ x: kotlin.Int)
public constructor Case5(/*0*/ x: kotlin.Long)
internal constructor Case5(/*0*/ x: kotlin.Short)
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
}
compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.fir.kt
0 → 100644
浏览文件 @
7c61ddc7
// LANGUAGE: +AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed
class
Case1
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case1
(
10
)
class
Inheritor2
:
Case1
(
"Hello"
)
}
sealed
class
Case2
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
val
x
:
Int
)<!>
{
// should be REDUNDANT_MODIFIER
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case2
(
10
)
class
Inheritor2
:
Case2
(
"Hello"
)
}
sealed
class
Case3
private
constructor
(
val
x
:
Int
)
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case3
(
10
)
// should OK
class
Inheritor2
:
Case3
(
"Hello"
)
}
class
Case3Inheritor3
:
<!
INAPPLICABLE_CANDIDATE
!>
Case3
<
!
>(
20
)
// should be an error in 1.6 (?)
sealed
class
Case4
{
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
x
:
Int
)<!>
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)<!>
class
Inheritor1
:
Case4
(
10
)
class
Inheritor2
:
Case4
(
"Hello"
)
}
sealed
class
Case5
()
{
private
constructor
(
x
:
Int
)
:
this
()
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
protected
constructor
(
x
:
Byte
)
:
this
()<!>
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
internal
constructor
(
x
:
Short
)
:
this
()<!>
<!
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
!>
public
constructor
(
x
:
Long
)
:
this
()<!>
constructor
(
x
:
Double
)
:
this
()
}
compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.kt
0 → 100644
浏览文件 @
7c61ddc7
// LANGUAGE: +AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed
class
Case1
(
val
x
:
Int
)
{
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case1
(
10
)
class
Inheritor2
:
Case1
(
"Hello"
)
}
sealed
class
Case2
protected
constructor
(
val
x
:
Int
)
{
// should be REDUNDANT_MODIFIER
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case2
(
10
)
class
Inheritor2
:
Case2
(
"Hello"
)
}
sealed
class
Case3
private
constructor
(
val
x
:
Int
)
{
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case3
(
10
)
// should OK
class
Inheritor2
:
Case3
(
"Hello"
)
}
class
Case3Inheritor3
:
Case3
(
20
)
// should be an error in 1.6 (?)
sealed
class
Case4
{
protected
constructor
(
x
:
Int
)
protected
constructor
(
s
:
String
)
:
this
(
s
.
length
)
class
Inheritor1
:
Case4
(
10
)
class
Inheritor2
:
Case4
(
"Hello"
)
}
sealed
class
Case5
()
{
private
constructor
(
x
:
Int
)
:
this
()
protected
constructor
(
x
:
Byte
)
:
this
()
<!
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
!>
internal
<!>
constructor
(
x
:
Short
)
:
this
()
<!
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
!>
public
<!>
constructor
(
x
:
Long
)
:
this
()
constructor
(
x
:
Double
)
:
this
()
}
compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.txt
0 → 100644
浏览文件 @
7c61ddc7
package
public sealed class Case1 {
protected constructor Case1(/*0*/ x: kotlin.Int)
protected constructor Case1(/*0*/ s: kotlin.String)
public final val x: kotlin.Int
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
public final class Inheritor1 : Case1 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public final class Inheritor2 : Case1 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
}
public sealed class Case2 {
protected constructor Case2(/*0*/ x: kotlin.Int)
protected constructor Case2(/*0*/ s: kotlin.String)
public final val x: kotlin.Int
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
public final class Inheritor1 : Case2 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public final class Inheritor2 : Case2 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
}
public sealed class Case3 {
private constructor Case3(/*0*/ x: kotlin.Int)
protected constructor Case3(/*0*/ s: kotlin.String)
public final val x: kotlin.Int
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
public final class Inheritor1 : Case3 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public final class Inheritor2 : Case3 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
}
public final class Case3Inheritor3 : Case3 {
public constructor Case3Inheritor3()
public final override /*1*/ /*fake_override*/ val x: kotlin.Int
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
}
public sealed class Case4 {
protected constructor Case4(/*0*/ x: kotlin.Int)
protected constructor Case4(/*0*/ s: kotlin.String)
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
public final class Inheritor1 : Case4 {
public constructor Inheritor1()
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
}
public final class Inheritor2 : Case4 {
public constructor Inheritor2()
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
}
}
public sealed class Case5 {
protected constructor Case5()
protected constructor Case5(/*0*/ x: kotlin.Byte)
protected constructor Case5(/*0*/ x: kotlin.Double)
private constructor Case5(/*0*/ x: kotlin.Int)
public constructor Case5(/*0*/ x: kotlin.Long)
internal constructor Case5(/*0*/ x: kotlin.Short)
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
}
compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
浏览文件 @
7c61ddc7
...
@@ -24601,6 +24601,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
...
@@ -24601,6 +24601,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/sealed/OperationWhen.kt");
runTest("compiler/testData/diagnostics/tests/sealed/OperationWhen.kt");
}
}
@Test
@TestMetadata("protectedConstructors_disabled.kt")
public void testProtectedConstructors_disabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/protectedConstructors_disabled.kt");
}
@Test
@TestMetadata("protectedConstructors_enabled.kt")
public void testProtectedConstructors_enabled() throws Exception {
runTest("compiler/testData/diagnostics/tests/sealed/protectedConstructors_enabled.kt");
}
@Test
@Test
@TestMetadata("RedundantAbstract.kt")
@TestMetadata("RedundantAbstract.kt")
public void testRedundantAbstract() throws Exception {
public void testRedundantAbstract() throws Exception {
idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt
浏览文件 @
7c61ddc7
...
@@ -149,6 +149,7 @@ class QuickFixRegistrar : QuickFixContributor {
...
@@ -149,6 +149,7 @@ class QuickFixRegistrar : QuickFixContributor {
REPEATED_MODIFIER
.
registerFactory
(
removeModifierFactory
)
REPEATED_MODIFIER
.
registerFactory
(
removeModifierFactory
)
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
.
registerFactory
(
removeModifierFactory
)
NON_PRIVATE_CONSTRUCTOR_IN_ENUM
.
registerFactory
(
removeModifierFactory
)
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
.
registerFactory
(
removeModifierFactory
)
NON_PRIVATE_CONSTRUCTOR_IN_SEALED
.
registerFactory
(
removeModifierFactory
)
NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
.
registerFactory
(
removeModifierFactory
)
TYPE_CANT_BE_USED_FOR_CONST_VAL
.
registerFactory
(
removeModifierFactory
)
TYPE_CANT_BE_USED_FOR_CONST_VAL
.
registerFactory
(
removeModifierFactory
)
DEPRECATED_BINARY_MOD
.
registerFactory
(
removeModifierFactory
)
DEPRECATED_BINARY_MOD
.
registerFactory
(
removeModifierFactory
)
DEPRECATED_BINARY_MOD
.
registerFactory
(
RenameModToRemFix
.
Factory
)
DEPRECATED_BINARY_MOD
.
registerFactory
(
RenameModToRemFix
.
Factory
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录