Skip to content

Commit 48576d5

Browse files
committed
Fixes scala#18123
1 parent 0a21ecf commit 48576d5

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,18 @@ object ProtoTypes {
106106
if !res then ctx.typerState.constraint = savedConstraint
107107
res
108108

109-
/** Constrain result with special case if `meth` is a transparent inlineable method in an inlineable context.
110-
* In that case, we should always succeed and not constrain type parameters in the expected type,
111-
* because the actual return type can be a subtype of the currently known return type.
109+
/** Constrain result with special case if `meth` is an inlineable method in an inlineable context.
110+
* In that case, if the method is transparent we should always succeed and not constrain type
111+
* parameters in the expected type, because the actual return type can be a subtype of the currently
112+
* known return type.
112113
* However, we should constrain parameters of the declared return type. This distinction is
113114
* achieved by replacing expected type parameters with wildcards.
114115
*/
115116
def constrainResult(meth: Symbol, mt: Type, pt: Type)(using Context): Boolean =
116-
if (Inlines.isInlineable(meth) && meth.is(Transparent)) {
117-
constrainResult(mt, wildApprox(pt))
118-
true
117+
if (Inlines.isInlineable(meth)) {
118+
val methodMatchedType = constrainResult(mt, wildApprox(pt))
119+
// do not constrain the result type of transparent inline methods
120+
meth.is(Transparent) || methodMatchedType
119121
}
120122
else constrainResult(mt, pt)
121123
}

tests/pos-macros/i18123.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pkg
2+
3+
trait P[+T]
4+
5+
extension [T](inline parse0: P[T])
6+
inline def | [V >: T](inline other: P[V]): P[V] = ???
7+
8+
extension [T](inline parse0: => P[T])
9+
inline def rep[V](inline min: Int = 0)(using repeater: Implicits.Repeater[T, V]): P[V] = ???
10+
11+
object Implicits:
12+
trait Repeater[-T, R]
13+
object Repeater:
14+
implicit def GenericRepeaterImplicit[T]: Repeater[T, Seq[T]] = ???
15+
16+
sealed trait RegexTree
17+
abstract class Node extends RegexTree
18+
class CharClassIntersection() extends Node
19+
20+
def classItem: P[RegexTree] = ???
21+
def charClassIntersection: P[CharClassIntersection] = ???
22+
23+
def x =
24+
(charClassIntersection.rep() | classItem.rep())

0 commit comments

Comments
 (0)