Skip to content

Fix #11118: check irrefutable pattern def in 3.0 #11131

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
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

object ClassDef extends ClassDefModule:
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = {
val dotc.ast.Trees.TypeDef(_, originalImpl: tpd.Template) = original
val dotc.ast.Trees.TypeDef(_, originalImpl: tpd.Template) = original: @unchecked
tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived, selfOpt.getOrElse(tpd.EmptyValDef), body))
}
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement]) =
Expand Down Expand Up @@ -956,7 +956,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def qualifier: Term = self.qualifier
def name: String = self.name.toString
def level: Int =
val NameKinds.OuterSelectName(_, levels) = self.name
val NameKinds.OuterSelectName(_, levels) = self.name: @unchecked
levels
end extension
end SelectOuterMethods
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
bc.aload(elementType)
}
else if (isArraySet(code)) {
val List(a1, a2) = args
val List(a1, a2) = args: @unchecked
genLoad(a1, INT)
genLoad(a2)
generatedType = UNIT
Expand Down Expand Up @@ -335,7 +335,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
// but I was able to derrive it by reading
// AbstractValidatingLambdaMetafactory.validateMetafactoryArgs

val DesugaredSelect(prefix, _) = fun
val DesugaredSelect(prefix, _) = fun: @unchecked
genLoad(prefix)
}

Expand Down Expand Up @@ -679,7 +679,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
lineNumber(app)
app match {
case Apply(_, args) if app.symbol eq defn.newArrayMethod =>
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args: @unchecked

generatedType = toTypeKind(c.typeValue)
mkArrayConstructorCall(generatedType.asArrayBType, app, dims)
Expand Down Expand Up @@ -756,7 +756,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
if (invokeStyle.hasInstance) genLoadQualifier(fun)
genLoadArguments(args, paramTKs(app))

val DesugaredSelect(qual, name) = fun // fun is a Select, also checked in genLoadQualifier
val DesugaredSelect(qual, name) = fun: @unchecked // fun is a Select, also checked in genLoadQualifier
val isArrayClone = name == nme.clone_ && qual.tpe.widen.isInstanceOf[JavaArrayType]
if (isArrayClone) {
// Special-case Array.clone, introduced in 36ef60e. The goal is to generate this call
Expand Down Expand Up @@ -799,7 +799,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
} // end of genApply()

private def genArrayValue(av: tpd.JavaSeqLiteral): BType = {
val ArrayValue(tpt, elems) = av
val ArrayValue(tpt, elems) = av: @unchecked

lineNumber(av)
genArray(elems, tpt)
Expand Down Expand Up @@ -1287,7 +1287,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
import ScalaPrimitivesOps.{ ZNOT, ZAND, ZOR, EQ }

// lhs and rhs of test
lazy val DesugaredSelect(lhs, _) = fun
lazy val DesugaredSelect(lhs, _) = fun: @unchecked
val rhs = if (args.isEmpty) tpd.EmptyTree else args.head // args.isEmpty only for ZNOT

def genZandOrZor(and: Boolean): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
// sorting ensures nested classes are listed after their enclosing class thus satisfying the Eclipse Java compiler
for (nestedClass <- allNestedClasses.sortBy(_.internalName.toString)) {
// Extract the innerClassEntry - we know it exists, enclosingNestedClassesChain only returns nested classes.
val Some(e) = nestedClass.innerClassAttributeEntry
val Some(e) = nestedClass.innerClassAttributeEntry: @unchecked
jclass.visitInnerClass(e.name, e.outerName, e.innerName, e.flags)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
val origSym = dd.symbol.asTerm
val newSym = makeStatifiedDefSymbol(origSym, origSym.name)
tpd.DefDef(newSym, { paramRefss =>
val selfParamRef :: regularParamRefs = paramRefss.head
val selfParamRef :: regularParamRefs = paramRefss.head: @unchecked
val enclosingClass = origSym.owner.asClass
new TreeTypeMap(
typeMap = _.substThis(enclosingClass, selfParamRef.symbol.termRef)
Expand Down
26 changes: 13 additions & 13 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ class JSCodeGen()(using genCtx: Context) {
}

val (beforeSuper, superCall :: afterSuper) =
bodyStats.span(!_.isInstanceOf[js.JSSuperConstructorCall])
bodyStats.span(!_.isInstanceOf[js.JSSuperConstructorCall]): @unchecked

assert(!beforeSuper.exists(_.isInstanceOf[js.VarDef]),
s"Trying to move a local VarDef after the super constructor call of a non-native JS class at ${body.pos}")
Expand Down Expand Up @@ -1728,7 +1728,7 @@ class JSCodeGen()(using genCtx: Context) {
*/
private def genSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos = tree.span
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree: @unchecked
val sym = fun.symbol

if (sym == defn.Any_getClass) {
Expand Down Expand Up @@ -1769,7 +1769,7 @@ class JSCodeGen()(using genCtx: Context) {
private def genApplyNew(tree: Apply): js.Tree = {
implicit val pos: SourcePosition = tree.sourcePos

val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree: @unchecked
val ctor = fun.symbol
val tpe = tpt.tpe

Expand Down Expand Up @@ -1818,7 +1818,7 @@ class JSCodeGen()(using genCtx: Context) {
acquireContextualJSClassValue { jsClassValue =>
implicit val pos: Position = tree.span

val Apply(fun @ Select(New(tpt), _), args) = tree
val Apply(fun @ Select(New(tpt), _), args) = tree: @unchecked
val cls = tpt.tpe.typeSymbol
val ctor = fun.symbol

Expand Down Expand Up @@ -2504,7 +2504,7 @@ class JSCodeGen()(using genCtx: Context) {

implicit val pos = tree.span

val Apply(fun, args) = tree
val Apply(fun, args) = tree: @unchecked
val arrayObj = qualifierOf(fun)

val genArray = genExpr(arrayObj)
Expand Down Expand Up @@ -2543,7 +2543,7 @@ class JSCodeGen()(using genCtx: Context) {
/* JavaScript is single-threaded, so we can drop the
* synchronization altogether.
*/
val Apply(fun, List(arg)) = tree
val Apply(fun, List(arg)) = tree: @unchecked
val receiver = qualifierOf(fun)

val genReceiver = genExpr(receiver)
Expand Down Expand Up @@ -2811,7 +2811,7 @@ class JSCodeGen()(using genCtx: Context) {
private def genJSSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
acquireContextualJSClassValue { explicitJSSuperClassValue =>
implicit val pos = tree.span
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree: @unchecked
val sym = fun.symbol

val genReceiver = genExpr(qual)
Expand Down Expand Up @@ -2887,7 +2887,7 @@ class JSCodeGen()(using genCtx: Context) {
/** Gen JS code for a switch-`Match`, which is translated into an IR `js.Match`. */
def genMatch(tree: Tree, isStat: Boolean): js.Tree = {
implicit val pos = tree.span
val Match(selector, cases) = tree
val Match(selector, cases) = tree: @unchecked

def abortMatch(msg: String): Nothing =
throw new FatalError(s"$msg in switch-like pattern match at ${tree.span}: $tree")
Expand Down Expand Up @@ -3098,7 +3098,7 @@ class JSCodeGen()(using genCtx: Context) {
val call = if (isStaticCall) {
genApplyStatic(sym, formalCaptures.map(_.ref) ::: actualParams)
} else {
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref): @unchecked
if (!sym.owner.isNonNativeJSClass || sym.isJSExposed)
genApplyMethodMaybeStatically(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
else
Expand All @@ -3110,7 +3110,7 @@ class JSCodeGen()(using genCtx: Context) {
val funInterfaceSym = functionalInterface.tpe.typeSymbol

if (jsdefn.isJSThisFunctionClass(funInterfaceSym)) {
val thisParam :: otherParams = formalParams
val thisParam :: otherParams = formalParams: @unchecked
js.Closure(
arrow = false,
formalCaptures,
Expand Down Expand Up @@ -3610,7 +3610,7 @@ class JSCodeGen()(using genCtx: Context) {
*/
private def genReflectiveCall(tree: Apply, isSelectDynamic: Boolean): js.Tree = {
implicit val pos = tree.span
val Apply(fun @ Select(receiver, _), args) = tree
val Apply(fun @ Select(receiver, _), args) = tree: @unchecked

val selectedValueTree = js.Apply(js.ApplyFlags.empty, genExpr(receiver),
js.MethodIdent(selectedValueMethodName), Nil)(jstpe.AnyType)
Expand Down Expand Up @@ -3875,7 +3875,7 @@ class JSCodeGen()(using genCtx: Context) {
private def genCaptureValuesFromFakeNewInstance(tree: Tree): List[js.Tree] = {
implicit val pos: Position = tree.span

val Apply(fun @ Select(New(_), _), args) = tree
val Apply(fun @ Select(New(_), _), args) = tree: @unchecked
val sym = fun.symbol

/* We use the same strategy as genActualJSArgs to detect which parameters were
Expand Down Expand Up @@ -4188,7 +4188,7 @@ class JSCodeGen()(using genCtx: Context) {
pathName.split('.').toList

def parseGlobalPath(pathName: String): Global = {
val globalRef :: path = parsePath(pathName)
val globalRef :: path = parsePath(pathName): @unchecked
Global(globalRef, path)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSConstructorGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ object JSConstructorGen {
(prepStats, applyCtor)
}
val js.ApplyStatic(_, _, js.MethodIdent(ctorName), js.This() :: ctorArgs) =
applyCtor
applyCtor: @unchecked
assert(ctorName.isConstructor,
s"unexpected super constructor call to non-constructor $ctorName at ${applyCtor.pos}")
(prepStats, ctorName, ctorArgs)
Expand Down Expand Up @@ -357,7 +357,7 @@ object JSConstructorGen {
case _: js.JSSuperConstructorCall => true
case _ => false
}
}
}: @unchecked

val ctorToChildren = secondaryCtors.map { ctor =>
findCtorForwarderCall(ctor.body.get) -> ctor
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
None
} else {
val formalArgsRegistry = new FormalArgsRegistry(1, false)
val List(arg) = formalArgsRegistry.genFormalArgs()
val List(arg) = formalArgsRegistry.genFormalArgs(): @unchecked
val body = genExportSameArgc(jsName, formalArgsRegistry, setters.map(Exported.apply), static, None)
Some((arg, body))
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ object desugar {

/** The expansion of a class definition. See inline comments for what is involved */
def classDef(cdef: TypeDef)(using Context): Tree = {
val impl @ Template(constr0, _, self, _) = cdef.rhs
val impl @ Template(constr0, _, self, _) = cdef.rhs: @unchecked
val className = normalizeName(cdef, impl).asTypeName
val parents = impl.parents
val mods = cdef.mods
Expand Down Expand Up @@ -750,7 +750,7 @@ object desugar {

enumCompanionRef match {
case ref: TermRefTree => // have the enum import watch the companion object
val (modVal: ValDef) :: _ = companions
val (modVal: ValDef) :: _ = companions: @unchecked
ref.watching(modVal)
case _ =>
}
Expand Down Expand Up @@ -1139,7 +1139,7 @@ object desugar {

/** Expand variable identifier x to x @ _ */
def patternVar(tree: Tree)(using Context): Bind = {
val Ident(name) = unsplice(tree)
val Ident(name) = unsplice(tree): @unchecked
Bind(name, Ident(nme.WILDCARD)).withSpan(tree.span)
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ class TreeTypeMap(

private def transformAllParamss(paramss: List[ParamClause]): (TreeTypeMap, List[ParamClause]) = paramss match
case params :: paramss1 =>
val (tmap1, params1: ParamClause) = (params: @unchecked) match
val (tmap1, params1: ParamClause) = (params: @unchecked) match {
case ValDefs(vparams) => transformDefs(vparams)
case TypeDefs(tparams) => transformDefs(tparams)
}: @unchecked
val (tmap2, paramss2) = tmap1.transformAllParamss(paramss1)
(tmap2, params1 :: paramss2)
case nil =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)

def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(using Context): TypeDef = {
val firstParent :: otherParents = cls.info.parents
val firstParent :: otherParents = cls.info.parents: @unchecked
val superRef =
if (cls.is(Trait)) TypeTree(firstParent)
else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object Settings {
}

def tryToSet(state: ArgsSummary): ArgsSummary = {
val ArgsSummary(sstate, arg :: args, errors, warnings) = state
val ArgsSummary(sstate, arg :: args, errors, warnings) = state: @unchecked
def update(value: Any, args: List[String]) =
var dangers = warnings
val value1 =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ object Annotations {

def unapply(ann: Annotation)(using Context): Option[Symbol] =
if (ann.symbol == defn.ChildAnnot) {
val AppliedType(_, (arg: NamedType) :: Nil) = ann.tree.tpe
val AppliedType(_, (arg: NamedType) :: Nil) = ann.tree.tpe: @unchecked
Some(arg.symbol)
}
else None
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ trait ConstraintHandling {
(c1 eq constraint)
|| {
constraint = c1
val TypeBounds(lo, hi) = constraint.entry(param)
val TypeBounds(lo, hi) = constraint.entry(param): @unchecked
isSub(lo, hi)
}
end addOneBound
Expand Down Expand Up @@ -226,7 +226,7 @@ trait ConstraintHandling {
*/
protected final def isSatisfiable(using Context): Boolean =
constraint.forallParams { param =>
val TypeBounds(lo, hi) = constraint.entry(param)
val TypeBounds(lo, hi) = constraint.entry(param): @unchecked
isSub(lo, hi) || {
report.log(i"sub fail $lo <:< $hi")
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
if (tl.isInstanceOf[HKLambda]) {
// HKLambdas are hash-consed, need to create an artificial difference by adding
// a LazyRef to a bound.
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos: @unchecked
paramInfos = TypeBounds(lo, LazyRef(hi)) :: pinfos1
}
ensureFresh(tl.newLikeThis(tl.paramNames, paramInfos, tl.resultType))
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def lubArgs(args1: List[Type], args2: List[Type], tparams: List[TypeParamInfo], canConstrain: Boolean = false): List[Type] =
tparams match {
case tparam :: tparamsRest =>
val arg1 :: args1Rest = args1
val arg2 :: args2Rest = args2
val arg1 :: args1Rest = args1: @unchecked
val arg2 :: args2Rest = args2: @unchecked
val common = singletonInterval(arg1, arg2)
val v = tparam.paramVarianceSign
val lubArg =
Expand Down Expand Up @@ -2054,8 +2054,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def glbArgs(args1: List[Type], args2: List[Type], tparams: List[TypeParamInfo]): List[Type] =
tparams match {
case tparam :: tparamsRest =>
val arg1 :: args1Rest = args1
val arg2 :: args2Rest = args2
val arg1 :: args1Rest = args1: @unchecked
val arg2 :: args2Rest = args2: @unchecked
val common = singletonInterval(arg1, arg2)
val v = tparam.paramVarianceSign
val glbArg =
Expand Down Expand Up @@ -2781,7 +2781,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
cas
}

val defn.MatchCase(pat, body) = cas1
val defn.MatchCase(pat, body) = cas1: @unchecked

if (isSubType(scrut, pat))
// `scrut` is a subtype of `pat`: *It's a Match!*
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
}

private def eraseArray(tp: Type)(using Context) = {
val defn.ArrayOf(elemtp) = tp
val defn.ArrayOf(elemtp) = tp: @unchecked
if (classify(elemtp).derivesFrom(defn.NullClass)) JavaArrayType(defn.ObjectType)
else if (isUnboundedGeneric(elemtp) && !isJava) defn.ObjectType
else JavaArrayType(erasureFn(isJava, semiEraseVCs = false, isConstructor, wildcardOK)(elemtp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class ClassfileParser(
*/
def normalizeConstructorParams() = innerClasses.get(currentClassName.toString) match {
case Some(entry) if !isStatic(entry.jflags) =>
val mt @ MethodTpe(paramNames, paramTypes, resultType) = denot.info
val mt @ MethodTpe(paramNames, paramTypes, resultType) = denot.info: @unchecked
var normalizedParamNames = paramNames.tail
var normalizedParamTypes = paramTypes.tail
if ((jflags & JAVA_ACC_SYNTHETIC) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TastyPickler(val rootCls: ClassSymbol) {
sections.foreach(_._2.assemble())

val nameBufferHash = TastyHash.pjwHash64(nameBuffer.bytes)
val treeSectionHash +: otherSectionHashes = sections.map(x => TastyHash.pjwHash64(x._2.bytes))
val treeSectionHash +: otherSectionHashes = sections.map(x => TastyHash.pjwHash64(x._2.bytes)): @unchecked

// Hash of name table and tree
val uuidLow: Long = nameBufferHash ^ treeSectionHash
Expand Down
Loading