Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve warning for wildcard matching non-nullable types (scala#21577) #21623

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HarrisL2
Copy link

Adds a more detailed warning message when a wildcard case is unreachable on an non-nullable type to suggest adding a nullable type annotation.

Fixes #21577

I have signed the CLA

Adds a more detailed warning message when a wildcard case is unreachable on an
non-nullable type to suggest adding a nullable type annotation.

Fixes scala#21577
@@ -215,6 +215,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
case TailrecNestedCallID //errorNumber: 199
case FinalLocalDefID // errorNumber: 200
case NonNamedArgumentInJavaAnnotationID // errorNumber: 201
case MatchCaseNonNullableWildcardWarningID // errorNumber: 202
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need another error?

@@ -928,7 +928,11 @@ object SpaceEngine {
&& isSubspace(covered, prev)
then {
val nullOnly = isNullable && i == len - 1 && isWildcardArg(pat)
val msg = if nullOnly then MatchCaseOnlyNullWarning() else MatchCaseUnreachable()
val wildcardNotNullable = i == len - 1 && isWildcardArg(pat)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work. It will catch other cases which are not related to null. You may want to modify isNullable, since a flexible type is considered "nullable" in terms of values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better warning for matching values with flexible types in explicit nulls
2 participants