Skip to content

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.

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