Skip to content

Add missing Erased flag to inline bindings #12027

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 1 commit into from
Apr 15, 2021
Merged
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ class Definitions {
@tu lazy val ImplicitAmbiguousAnnot: ClassSymbol = requiredClass("scala.annotation.implicitAmbiguous")
@tu lazy val ImplicitNotFoundAnnot: ClassSymbol = requiredClass("scala.annotation.implicitNotFound")
@tu lazy val InlineParamAnnot: ClassSymbol = requiredClass("scala.annotation.internal.InlineParam")
@tu lazy val ErasedParamAnnot: ClassSymbol = requiredClass("scala.annotation.internal.ErasedParam")
@tu lazy val InvariantBetweenAnnot: ClassSymbol = requiredClass("scala.annotation.internal.InvariantBetween")
@tu lazy val MainAnnot: ClassSymbol = requiredClass("scala.main")
@tu lazy val MigrationAnnot: ClassSymbol = requiredClass("scala.annotation.migration")
Expand Down
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3640,9 +3640,15 @@ object Types {
case ExprType(resType) => ExprType(AnnotatedType(resType, Annotation(defn.InlineParamAnnot)))
case _ => AnnotatedType(tp, Annotation(defn.InlineParamAnnot))
}
def translateErased(tp: Type): Type = tp match {
case ExprType(resType) => ExprType(AnnotatedType(resType, Annotation(defn.ErasedParamAnnot)))
case _ => AnnotatedType(tp, Annotation(defn.ErasedParamAnnot))
}
def paramInfo(param: Symbol) = {
val paramType = param.info.annotatedToRepeated
if (param.is(Inline)) translateInline(paramType) else paramType
var paramType = param.info.annotatedToRepeated
if (param.is(Inline)) paramType = translateInline(paramType)
if (param.is(Erased)) paramType = translateErased(paramType)
paramType
}

apply(params.map(_.name.asTermName))(
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
toTextGlobal(tp.resultType)
}
case AnnotatedType(tpe, annot) =>
if annot.symbol == defn.InlineParamAnnot then toText(tpe)
if annot.symbol == defn.InlineParamAnnot || annot.symbol == defn.ErasedParamAnnot then toText(tpe)
else toTextLocal(tpe) ~ " " ~ toText(annot)
case tp: TypeVar =>
if (tp.isInstantiated)
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
var bindingFlags: FlagSet = InlineProxy
if formal.widenExpr.hasAnnotation(defn.InlineParamAnnot) then
bindingFlags |= Inline
if formal.widenExpr.hasAnnotation(defn.ErasedParamAnnot) then
bindingFlags |= Erased
if isByName then
bindingFlags |= Method
val boundSym = newSym(InlineBinderName.fresh(name.asTermName), bindingFlags, bindingType).asTerm
Expand Down
6 changes: 6 additions & 0 deletions library/src/scala/annotation/internal/ErasedParam.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package scala.annotation.internal

import scala.annotation.Annotation

/** An annotation produced by Namer to indicate an erased parameter */
final class ErasedParam() extends Annotation
23 changes: 23 additions & 0 deletions tests/run-custom-args/erased/i11996.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
final class UnivEq[A]

object UnivEq:
erased def force[A]: UnivEq[A] =
compiletime.erasedValue

extension [A](a: A)
inline def ==*[B >: A](b: B)(using erased UnivEq[B]): Boolean = a == b
inline def !=*[B >: A](b: B)(using erased UnivEq[B]): Boolean = a != b

case class I(i: Int)

@main def Test = {
def test[A](a: A, b: A): Unit = {
erased given UnivEq[A] = UnivEq.force[A]
println(a ==* a)
println(a !=* b)
}
println("Test starting...")
test(I(1), I(2)) // error
test(1, 2)
test(true, false)
}