Skip to content

Warn on use of inferred quote type variable bounds #16932

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

Conversation

nicolasstucki
Copy link
Contributor

This kind of inference is not reliable in general. We can only consider the bounds from type constructor where the type variable is defined but any other constraints are ignored. Therefore it is not possible to properly infer the type bounds of the type variable.

The solution is simple, write the bounds explicitly and just check that those bounds conform to the use site of the type variable.

@nicolasstucki nicolasstucki marked this pull request as ready for review February 17, 2023 07:50
@nicolasstucki
Copy link
Contributor Author

We also need #16942 for this message to make sense in type patterns.

@@ -159,6 +159,8 @@ trait QuotesAndSplices {
case _ => TypeBounds.empty
val typeSym = newSymbol(spliceOwner(ctx), name, EmptyFlags, typeSymInfo, NoSymbol, tree.span)
typeSym.addAnnotation(Annotation(New(ref(defn.QuotedRuntimePatterns_patternTypeAnnot.typeRef)).withSpan(tree.span)))
if !(typeSymInfo =:= TypeBounds.empty) then
report.warning(em"Type variable `$tree` has partially inferred bounds$pt.\n\nConsider defining bounds explicitly `'{ $typeSym$pt; ... }`", tree.srcPos)
Copy link
Contributor Author

@nicolasstucki nicolasstucki Feb 17, 2023

Choose a reason for hiding this comment

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

We should write '[ type t <: T; ... ] for type patterns once we support #16942

@nicolasstucki nicolasstucki self-assigned this Mar 2, 2023
@nicolasstucki nicolasstucki marked this pull request as draft March 2, 2023 10:34
This kind of inference is not reliable in general. We can only consider
the bounds from type constructor where the type variable is defined but
any other constraints are ignored. Therefore it is not possible to
properly infer the type bounds of the type variable.

The solution is simple, write the bounds explicitly and just check that
those bounds conform to the use site of the type variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant