Skip to content

Commit

Permalink
Revert broken changes with transparent inline (#19922)
Browse files Browse the repository at this point in the history
Proposed in
#19415 (comment)

Fixes #19415

Reverts #18130 and
#17924.

 #18130 is still closed as it was introduced by #17924.

This reopens #9685
  • Loading branch information
nicolasstucki committed Mar 12, 2024
2 parents 02c2a6e + 5bc43d3 commit f663a8b
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 115 deletions.
2 changes: 1 addition & 1 deletion community-build/community-projects/munit
21 changes: 3 additions & 18 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Expand Up @@ -17,8 +17,6 @@ import Inferencing.*
import ErrorReporting.*
import util.SourceFile
import TypeComparer.necessarySubType
import dotty.tools.dotc.core.Flags.Transparent
import dotty.tools.dotc.config.{ Feature, SourceVersion }

import scala.annotation.internal.sharable
import dotty.tools.dotc.util.Spans.{NoSpan, Span}
Expand Down Expand Up @@ -108,29 +106,16 @@ object ProtoTypes {
if !res then ctx.typerState.constraint = savedConstraint
res

/** Constrain result with special case if `meth` is a transparent inlineable method in an inlineable context.
/** Constrain result with special case if `meth` is an inlineable method in an inlineable context.
* In that case, we should always succeed and not constrain type parameters in the expected type,
* because the actual return type can be a subtype of the currently known return type.
* However, we should constrain parameters of the declared return type. This distinction is
* achieved by replacing expected type parameters with wildcards.
*/
def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean =
if (Inlines.isInlineable(meth)) {
// Stricter behaviour in 3.4+: do not apply `wildApprox` to non-transparent inlines
if (Feature.sourceVersion.isAtLeast(SourceVersion.`3.4`)) {
if (meth.is(Transparent)) {
constrainResult(mt, wildApprox(pt))
// do not constrain the result type of transparent inline methods
true
} else {
constrainResult(mt, pt)
}
} else {
// Best-effort to fix https://github.com/scala/scala3/issues/9685 in the 3.3.x series
// while preserving source compatibility as much as possible
val methodMatchedType = constrainResult(mt, wildApprox(pt))
meth.is(Transparent) || methodMatchedType
}
constrainResult(mt, wildApprox(pt))
true
}
else constrainResult(mt, pt)
}
Expand Down
27 changes: 0 additions & 27 deletions tests/neg-macros/i18174.scala

This file was deleted.

9 changes: 0 additions & 9 deletions tests/neg-macros/i9685bis.check

This file was deleted.

23 changes: 0 additions & 23 deletions tests/neg-macros/i9685bis.scala

This file was deleted.

9 changes: 0 additions & 9 deletions tests/neg/i9685bis.check

This file was deleted.

25 changes: 0 additions & 25 deletions tests/neg/i9685bis.scala

This file was deleted.

2 changes: 0 additions & 2 deletions tests/pos-macros/i18123.scala → tests/pos/i18123.scala
@@ -1,8 +1,6 @@
// may not compile anymore in Scala 3.4+
package pkg

import scala.language.`3.3`

trait P[+T]

extension [T](inline parse0: P[T])
Expand Down

0 comments on commit f663a8b

Please sign in to comment.