Skip to content

Commit

Permalink
Fix stability check for inline parameters
Browse files Browse the repository at this point in the history
Inline parameters are not stable. Two references to the same parameter
may not be idempotent.
  • Loading branch information
nicolasstucki committed Jul 4, 2022
1 parent 7d6d42f commit ab279ab
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ object SymDenotations {
* So the first call to a stable member might fail and/or produce side effects.
*/
final def isStableMember(using Context): Boolean = {
def isUnstableValue = isOneOf(UnstableValueFlags) || info.isInstanceOf[ExprType]
def isUnstableValue = isOneOf(UnstableValueFlags) || info.isInstanceOf[ExprType] || isAllOf(InlineParam)
isType || is(StableRealizable) || exists && !isUnstableValue
}

Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scala.reflect.TypeTest
* }
* ```
*/
transparent inline def quotes(using inline q: Quotes): q.type = q
transparent inline def quotes(using q: Quotes): q.type = q

/** Quotation context provided by a macro expansion or in the scope of `scala.quoted.staging.run`.
* Used to perform all operations on quoted `Expr` or `Type`.
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/runtime/stdLibPatches/Predef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Predef:
* @tparam T the type of the value to be summoned
* @return the given value typed: the provided type parameter
*/
transparent inline def summon[T](using inline x: T): x.type = x
transparent inline def summon[T](using inline x: T): T = x

// Extension methods for working with explicit nulls

Expand Down
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends DocTastyInspe

def processCompilationUnit(using Quotes)(root: reflect.Tree): Unit = ()

override def postProcess(using Quotes): Unit =
override def postProcess(using q: Quotes): Unit =
// hack into the compiler to get a list of all top-level trees
// in principle, to do this, one would collect trees in processCompilationUnit
// however, path-dependent types disallow doing so w/o using casts
Expand Down
2 changes: 1 addition & 1 deletion scaladoc/src/dotty/tools/scaladoc/tasty/reflect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package tasty
import scala.quoted._

/** Shorthand for `quotes.reflect` */
transparent inline def reflect(using inline q: Quotes): q.reflect.type = q.reflect
transparent inline def reflect(using q: Quotes): q.reflect.type = q.reflect
6 changes: 6 additions & 0 deletions tests/neg/inline-param-unstable-path.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
inline val a = 3
inline def f(inline x: Int, y: Int, z: => Int): Unit =
val x2: x.type = x // error: (x : Int) is not a valid singleton type, since it is not an immutable path
val y2: y.type = y
val z2: z.type = z // error: (z : Int) is not a valid singleton type, since it is not an immutable path
val a2: a.type = a

0 comments on commit ab279ab

Please sign in to comment.