-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error if class or enum are statically referenced (#643)
Closes partially #543 ### Summary of Changes Show an error if a class or enum is statically referenced. They must only be referenced to access one of their members/variants or to call them¹. ----- ¹ If they are not callable, we already show another error. --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
f5ee1bd
commit 8b076e7
Showing
6 changed files
with
154 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 21 additions & 8 deletions
29
tests/resources/typing/expressions/member accesses/to other/main.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
package tests.typing.expressions.memberAccesses.toOther | ||
|
||
class C { | ||
class C() { | ||
// $TEST$ equivalence_class nonNullableMember | ||
static attr »nonNullableMember«: Int | ||
attr »nonNullableMember«: Int | ||
|
||
// $TEST$ equivalence_class nullableMember | ||
static attr »nullableMember«: Any? | ||
attr »nullableMember«: Any? | ||
} | ||
|
||
fun nullableC() -> result: C? | ||
|
||
pipeline myPipeline { | ||
// $TEST$ equivalence_class nonNullableMember | ||
»C.nonNullableMember«; | ||
»C().nonNullableMember«; | ||
// $TEST$ equivalence_class nullableMember | ||
»C.nullableMember«; | ||
»C().nullableMember«; | ||
|
||
// $TEST$ equivalence_class nonNullableMember | ||
»C()?.nonNullableMember«; | ||
// $TEST$ equivalence_class nullableMember | ||
»C()?.nullableMember«; | ||
|
||
|
||
// $TEST$ equivalence_class nonNullableMember | ||
»nullableC().nonNullableMember«; | ||
// $TEST$ equivalence_class nullableMember | ||
»nullableC().nullableMember«; | ||
|
||
// $TEST$ serialization Int? | ||
»C?.nonNullableMember«; | ||
// $TEST$ serialization Any? | ||
»C?.nullableMember«; | ||
»nullableC()?.nonNullableMember«; | ||
// $TEST$ equivalence_class nullableMember | ||
»nullableC()?.nullableMember«; | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/resources/validation/other/expressions/references/static class reference/main.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tests.validation.other.expressions.references.staticClassReference | ||
|
||
class ClassWithConstructor() | ||
|
||
class ClassWithoutConstructor | ||
|
||
class ClassWithStaticMembers { | ||
static attr myAttribute: Int | ||
|
||
class InnerClassWithConstructor() { | ||
static attr myAttribute: Int | ||
} | ||
|
||
class InnerClassWithoutConstructor | ||
} | ||
|
||
pipeline test { | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»Unresolved«; | ||
// $TEST$ error "A class must not be statically referenced." | ||
»ClassWithConstructor«; | ||
// $TEST$ error "A class must not be statically referenced." | ||
»ClassWithoutConstructor«; | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»ClassWithoutConstructor«(); | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»ClassWithConstructor«(); | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»ClassWithStaticMembers«.myAttribute; | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»ClassWithStaticMembers«.unresolved; | ||
// $TEST$ no error "A class must not be statically referenced." | ||
// $TEST$ error "A class must not be statically referenced." | ||
»ClassWithStaticMembers«.»InnerClassWithConstructor«; | ||
// $TEST$ no error "A class must not be statically referenced." | ||
// $TEST$ error "A class must not be statically referenced." | ||
»ClassWithStaticMembers«.»InnerClassWithoutConstructor«; | ||
// $TEST$ no error "A class must not be statically referenced." | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»ClassWithStaticMembers«.»InnerClassWithConstructor«(); | ||
// $TEST$ no error "A class must not be statically referenced." | ||
// $TEST$ no error "A class must not be statically referenced." | ||
»ClassWithStaticMembers«.»InnerClassWithConstructor«.myAttribute; | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/resources/validation/other/expressions/references/static enum reference/main.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package tests.validation.other.expressions.references.staticEnumReference | ||
|
||
enum Enum { | ||
Variant | ||
} | ||
|
||
class ClassWithEnum { | ||
enum Enum { | ||
Variant | ||
} | ||
|
||
class ClassWithEnum { | ||
enum Enum { | ||
Variant | ||
} | ||
} | ||
} | ||
|
||
pipeline test { | ||
// $TEST$ no error "An enum must not be statically referenced." | ||
»Unresolved«; | ||
// $TEST$ error "An enum must not be statically referenced." | ||
»Enum«; | ||
// $TEST$ no error "An enum must not be statically referenced." | ||
»Enum«(); | ||
// $TEST$ no error "An enum must not be statically referenced." | ||
»Enum«.Variant; | ||
// $TEST$ no error "An enum must not be statically referenced." | ||
»Enum«.unresolved; | ||
// $TEST$ error "An enum must not be statically referenced." | ||
ClassWithEnum.»Enum«; | ||
// $TEST$ no error "An enum must not be statically referenced." | ||
ClassWithEnum.»Enum«.Variant; | ||
// $TEST$ error "An enum must not be statically referenced." | ||
ClassWithEnum.ClassWithEnum.»Enum«; | ||
// $TEST$ no error "An enum must not be statically referenced." | ||
ClassWithEnum.ClassWithEnum.»Enum«.Variant; | ||
} |