Skip to content

Commit 76a51d2

Browse files
committed
Prohibit type parameters with type bounds
1 parent d5fab3c commit 76a51d2

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,6 @@ trait Applications extends Compatibility {
11481148
if (ctx.mode.is(Mode.Pattern))
11491149
return errorTree(tree, em"invalid pattern")
11501150

1151-
tree.fun match
1152-
case _: untpd.SplicePattern => return typedTypeAppliedSplice(tree, pt)
1153-
case _ =>
1154-
11551151
val isNamed = hasNamedArg(tree.args)
11561152
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
11571153
record("typedTypeApply")

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,28 @@ trait QuotesAndSplices {
120120
}
121121
}
122122
val typedTypeargs = tree.typeargs.map {
123-
case arg: untpd.Ident =>
124-
typedType(arg) // TODO-18271: Is this appropriate?
123+
case typearg: untpd.Ident =>
124+
val typedTypearg = typedType(typearg) // TODO-18271: Is this appropriate?
125+
/* TODO-18271: Allow type bounds?
126+
* (NOTE: Needs non-trivial extension to type system)
127+
*/
128+
val bounds = ctx.gadt.fullBounds(typedTypearg.symbol)
129+
if bounds != null && bounds != TypeBounds.empty then
130+
report.error("Type arguments to Open pattern are expected to have no bounds", typearg.srcPos)
131+
typedTypearg
125132
case arg =>
126133
report.error("Open pattern expected an identifier", arg.srcPos)
127134
EmptyTree
128135
}
129136
for arg <- typedArgs if arg.symbol.is(Mutable) do // TODO support these patterns. Possibly using scala.quoted.util.Var
130137
report.error("References to `var`s cannot be used in higher-order pattern", arg.srcPos)
131138
val argTypes = typedArgs.map(_.tpe.widenTermRefExpr)
132-
// TODO-18271: Does PolyProto work here as expected?
133139
val patType = (tree.typeargs.isEmpty, tree.args.isEmpty) match
134140
case (true, true) => pt
135-
case (true, false) => defn.FunctionOf(argTypes, pt)
136-
case (false, true) => PolyFunctionOf(typedTypeargs.tpes, Nil, pt)
137-
case (false, false) => PolyFunctionOf(typedTypeargs.tpes, argTypes, pt)
141+
case (true, false) =>
142+
defn.FunctionOf(argTypes, pt)
143+
case (false, _) =>
144+
PolyFunctionOf(typedTypeargs.tpes, argTypes, pt)
138145

139146
val pat = typedPattern(tree.body, defn.QuotedExprClass.typeRef.appliedTo(patType))(using quotePatternSpliceContext)
140147
val baseType = pat.tpe.baseType(defn.QuotedExprClass)
@@ -391,17 +398,13 @@ object QuotesAndSplices {
391398
*/
392399
def apply(typeargs: List[Type], args: List[Type], resultType: Type)(using Context): Type =
393400
val typeargs1 = PolyType.syntheticParamNames(typeargs.length)
394-
val bounds = typeargs map { tpe =>
395-
ctx.gadt.fullBounds(tpe.typeSymbol) match
396-
case b:TypeBounds => b
397-
case _ => TypeBounds.empty
398-
}
399-
println(s"bounds = ${bounds map (_.show)}")
401+
402+
val bounds = typeargs map (_ => TypeBounds.empty)
400403
val resultTypeExp = (pt: PolyType) => {
401404
val fromSymbols = typeargs map (_.typeSymbol)
402405
val args1 = args map (_.subst(fromSymbols, pt.paramRefs))
403406
val resultType1 = resultType.subst(fromSymbols, pt.paramRefs)
404-
MethodType(args1, resultType)
407+
MethodType(args1, resultType1)
405408
}
406409
val tpe = PolyType(typeargs1)(_ => bounds, resultTypeExp)
407410
RefinedType(defn.PolyFunctionType, nme.apply, tpe)

0 commit comments

Comments
 (0)