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

Traverse the types to find experimental references #14047

Merged
merged 2 commits into from Dec 13, 2021

Conversation

nicolasstucki
Copy link
Contributor

Fixes #14034

@@ -1339,7 +1339,18 @@ class RefChecks extends MiniPhase { thisPhase =>
}

override def transformTypeTree(tree: TypeTree)(using Context): TypeTree = {
checkExperimental(tree.symbol, tree.srcPos)
object CheckExperimental extends TypeTraverser {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any way to get more precise positions of errors with with approach? Now if an experimental type is found inside another type (which could be e.g. a complex match type spanning across multiple lines) the entire type expression will be marked as an error instead of just the reference to the experimental type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that at this phase we only have a TypeTree for those types. We should see if it is possible to keep them around. But maybe later.

@nicolasstucki
Copy link
Contributor Author

I extended the fix to cover @deprecated missing checks.

@prolativ
Copy link
Contributor

prolativ commented Dec 7, 2021

Actually I started to wonder now: is it allowed to refer to deprecated methods/types/etc. from inside of other deprecated definitions just as it's considered OK to refer to experimentals from other experimentals? Or does this cause an error/warning?

@nicolasstucki nicolasstucki force-pushed the fix-#14034 branch 2 times, most recently from 8784f31 to 3bdbc60 Compare December 9, 2021 14:39
Undesired references can be to deprecated or experimental terms or types.

Fixes scala#14034
@nicolasstucki
Copy link
Contributor Author

Actually I started to wonder now: is it allowed to refer to deprecated methods/types/etc. from inside of other deprecated definitions just as it's considered OK to refer to experimentals from other experimentals? Or does this cause an error/warning?

We should emit the warning because the methods might be removed in any order in the future. If your deprecated definition depends on a deprecated definition that will disappear before your does, you should know about it to let you update your function and still support it correctly until it is fully removed.

@prolativ prolativ self-requested a review December 10, 2021 11:24
@@ -1339,7 +1339,16 @@ class RefChecks extends MiniPhase { thisPhase =>
}

override def transformTypeTree(tree: TypeTree)(using Context): TypeTree = {
checkExperimental(tree.symbol, tree.srcPos)
val tpe = tree.tpe
tpe.dealias.foreachPart {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's consider a situation like this:

object LibApi:
  @deprecated
  trait OldName
  
  type NewName = OldName 

when the author of a library decided to rename a trait so they created an nondeprecated type alias pointing to it. Should we raise a warning in this case as well?
Probably it would be better for the author to have

object LibApi:
  @deprecated
  type OldName = NewName
  
  trait NewName

instead but can/should we enforce such a solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good example. We should not dealias here.

@nicolasstucki nicolasstucki merged commit 4b74afb into scala:master Dec 13, 2021
@nicolasstucki nicolasstucki deleted the fix-#14034 branch December 13, 2021 19:33
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 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.

Usages of experimentals are not always checked in types
3 participants