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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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

val pat = typedPattern(expr, defn.QuotedTypeClass.typeRef.appliedTo(typeSym.typeRef))(
using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx)))
pat.select(tpnme.Underlying)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Error: tests/neg-custom-args/fatal-warnings/quote-type-var-with-bounds.scala:9:18 -----------------------------------
9 | case '{ $x: C[t] } => // error
| ^
| Type variable `t` has partially inferred bounds <: Int.
|
| Consider defining bounds explicitly `'{ type t <: Int; ... }`
-- Error: tests/neg-custom-args/fatal-warnings/quote-type-var-with-bounds.scala:10:18 ----------------------------------
10 | case '{ $x: D[t] } => // error
| ^
| Type variable `t` has partially inferred bounds >: Null <: String.
|
| Consider defining bounds explicitly `'{ type t >: Null <: String; ... }`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.quoted.*

class C[T <: Int]
class D[T >: Null <: String]

def test(e: Expr[Any])(using Quotes) =
e match
case '{ $x: t } =>
case '{ $x: C[t] } => // error
case '{ $x: D[t] } => // error
case '{ type t <: Int; $x: C[`t`] } =>