Skip to content

Fix more problems detected by fuzzing in #4389 #4411

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

Merged
merged 13 commits into from
Apr 30, 2018
Merged
20 changes: 10 additions & 10 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ object Types {
/** Is this type a value type? */
final def isValueType: Boolean = this.isInstanceOf[ValueType]

/** Is the is value type or type lambda? */
/** Is this a value type or a type lambda? */
final def isValueTypeOrLambda: Boolean = isValueType || this.isInstanceOf[TypeLambda]

/** Is this a value type or a wildcard? */
final def isValueTypeOrWildcard: Boolean = isValueType || this.isInstanceOf[WildcardType]

/** Does this type denote a stable reference (i.e. singleton type)? */
final def isStable(implicit ctx: Context): Boolean = stripTypeVar match {
case tp: TermRef => tp.termSymbol.isStable && tp.prefix.isStable || tp.info.isStable
Expand Down Expand Up @@ -1524,11 +1527,8 @@ object Types {
/** A marker trait for types that can be types of values or prototypes of value types */
trait ValueTypeOrProto extends TermType

/** A marker trait for types that can be types of values or wildcards */
trait ValueTypeOrWildcard extends TermType

/** A marker trait for types that can be types of values or that are higher-kinded */
trait ValueType extends ValueTypeOrProto with ValueTypeOrWildcard
trait ValueType extends ValueTypeOrProto

/** A marker trait for types that are guaranteed to contain only a
* single non-null value (they might contain null in addition).
Expand Down Expand Up @@ -2480,8 +2480,8 @@ object Types {

object AndType {
def apply(tp1: Type, tp2: Type)(implicit ctx: Context): AndType = {
assert(tp1.isInstanceOf[ValueTypeOrWildcard] &&
tp2.isInstanceOf[ValueTypeOrWildcard], i"$tp1 & $tp2 / " + s"$tp1 & $tp2")
assert(tp1.isValueTypeOrWildcard &&
tp2.isValueTypeOrWildcard, i"$tp1 & $tp2 / " + s"$tp1 & $tp2")
unchecked(tp1, tp2)
}

Expand Down Expand Up @@ -2525,8 +2525,8 @@ object Types {
myBaseClasses
}

assert(tp1.isInstanceOf[ValueTypeOrWildcard] &&
tp2.isInstanceOf[ValueTypeOrWildcard], s"$tp1 $tp2")
assert(tp1.isValueTypeOrWildcard &&
tp2.isValueTypeOrWildcard, s"$tp1 $tp2")

private[this] var myJoin: Type = _
private[this] var myJoinPeriod: Period = Nowhere
Expand Down Expand Up @@ -3757,7 +3757,7 @@ object Types {
object TryDynamicCallType extends FlexType

/** Wildcard type, possibly with bounds */
abstract case class WildcardType(optBounds: Type) extends CachedGroundType with ValueTypeOrWildcard {
abstract case class WildcardType(optBounds: Type) extends CachedGroundType with TermType {
def derivedWildcardType(optBounds: Type)(implicit ctx: Context) =
if (optBounds eq this.optBounds) this
else if (!optBounds.exists) WildcardType
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,18 @@ object ProtoTypes {
}

/** Create a new TypeVar that represents a dependent method parameter singleton */
def newDepTypeVar(tp: Type)(implicit ctx: Context): TypeVar =
def newDepTypeVar(tp: Type)(implicit ctx: Context): TypeVar = {
newTypeVar(TypeBounds.upper(AndType(tp.widenExpr, defn.SingletonClass.typeRef)))

}
/** The result type of `mt`, where all references to parameters of `mt` are
* replaced by either wildcards (if typevarsMissContext) or TypeParamRefs.
*/
def resultTypeApprox(mt: MethodType)(implicit ctx: Context): Type =
if (mt.isResultDependent) {
def replacement(tp: Type) =
if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepTypeVar(tp)
if (ctx.mode.is(Mode.TypevarsMissContext) ||
!tp.widenExpr.isValueTypeOrWildcard) WildcardType
Copy link
Member

@smarter smarter Apr 29, 2018

Choose a reason for hiding this comment

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

Here too, the error recovery case could be more explicit:

if (!tp.widenExpr.isValueTypeOrWildcard) {
  assert(ctx.reporter.errorsReported)
  WildcardType
}
else if (ctx.mode.is(Mode.TypevarsMissContext))
  WildcardType
else ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same response: I am not sure the error would always be detected beforehand.

else newDepTypeVar(tp)
mt.resultType.substParams(mt, mt.paramInfos.map(replacement))
}
else mt.resultType
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/parser-stability-17.scala
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
trait x0[] { x0: x0 => }
class x0[x1] extends x0[x0 x0] x2 x0
trait x0[] { x0: x0 => } // error // error
class x0[x1] extends x0[x0 x0] x2 x0 // error // error
4 changes: 4 additions & 0 deletions tests/neg/parser-stability-19.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object x0 {
case class x0[] // error // error
def x0( ) ] // error // error
def x0 ( x0:x0 ):x0.type = x1 x0 // error // error // error