Skip to content
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

Revert broken changes with transparent inline #19922

Merged
merged 3 commits into from
Mar 12, 2024
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
21 changes: 3 additions & 18 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Loading