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

Expose reason for unchecked local class warning #16086

Merged
merged 2 commits into from
Oct 17, 2022

Conversation

dwijnand
Copy link
Member

No description provided.

@som-snytt
Copy link
Contributor

The tabloid headline: "Unchecked Warning: Exposed!"

@dwijnand dwijnand marked this pull request as ready for review September 22, 2022 07:24
@dwijnand dwijnand requested a review from odersky September 24, 2022 11:45
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

* 1. if `X <:< P`, TRUE
* 2. if `P` is a singleton type, TRUE
* 3. if `P` refers to an abstract type member or type parameter, FALSE
* 1. if `X <:< P`, ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefix this with a comment that the method returns a string explaining why the type is not checkable, or the empty string if it is checkable.

if (!isTrusted && !checkable(expr.tpe, argType, tree.span))
report.uncheckedWarning(i"the type test for $argType cannot be checked at runtime", expr.srcPos)
transformTypeTest(expr, tree.args.head.tpe,
val unchecked = expr.tpe.widenTermRefExpr.hasAnnotation(defn.UncheckedAnnot)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to encode isTrusted as empty strings.

I think renaming checkable to whyUncheckable and changing the logic as below would make things clearer.

val isUnchecked = expr.tpe.widenTermRefExpr.hasAnnotation(defn.UncheckedAnnot)
if !isTrusted && !isUnchecked then
  val whyNot = whyUncheckable(expr.tpe, argType, tree.span)
  if !whyNot.isEmpty then 
    report.uncheckedWarning

@odersky odersky assigned dwijnand and unassigned odersky Oct 10, 2022
@dwijnand dwijnand enabled auto-merge October 10, 2022 15:44
@dwijnand dwijnand disabled auto-merge October 17, 2022 15:06
@dwijnand dwijnand merged commit c7ac8dc into scala:main Oct 17, 2022
@dwijnand dwijnand deleted the unchecked-bc branch October 17, 2022 15:07
@dwijnand dwijnand changed the title Expose reason for unchecked warning Expose reason for unchecked local class warning Oct 28, 2022
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
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.

Type test for local class cannot be checked at runtime in 3.2.1-RC1
4 participants