Skip to content

Commit fbbae09

Browse files
HarrisL2olhotak
authored andcommitted
Handle FlexibleTypes in asContextFunctionType
Fixes #23845
1 parent d84dc5c commit fbbae09

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,8 @@ class Definitions {
19961996
asContextFunctionType(TypeComparer.bounds(tp1).hiBound)
19971997
case tp1 @ PolyFunctionOf(mt: MethodType) if mt.isContextualMethod =>
19981998
tp1
1999+
case tp1: FlexibleType =>
2000+
asContextFunctionType(tp1.underlying)
19992001
case tp1 =>
20002002
if tp1.typeSymbol.name.isContextFunction && isFunctionNType(tp1) then tp1
20012003
else NoType

tests/explicit-nulls/flexible-unpickle/Flexible_2.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import unsafeNulls.Foo.*
22
import unsafeNulls.Unsafe_1
3-
import unsafeNulls.{A, B, C, F, G, H, I, J, L, M}
3+
import unsafeNulls.{A, B, C, F, G, H, I, J, L, M, S, T, U, expects}
44
import scala.reflect.Selectable.reflectiveSelectable
5+
import scala.quoted.*
56

67
class Inherit_1 extends Unsafe_1 {
78
override def foo(s: String): String = s
@@ -34,6 +35,8 @@ case class cc()
3435
class K(val b: String) extends J(b) {
3536
}
3637

38+
def typeNameMacro[A: Type](using Quotes) = Expr(Type.show[A])
39+
3740
@main
3841
def Flexible_2() =
3942
val s2: String | Null = "foo"
@@ -97,3 +100,12 @@ def Flexible_2() =
97100

98101
val m: String = M.test(null)
99102

103+
// i23845
104+
transparent inline def typeName[A]: String = ${typeNameMacro[A]}
105+
106+
implicit val givenT: T = ???
107+
def alphaTypeNameMacro[A: S](using T) = U(S.show[A])
108+
def res[A] = {
109+
implicit val givenS: S[A] = ???
110+
expects(alphaTypeNameMacro[A])
111+
}

tests/explicit-nulls/flexible-unpickle/Unsafe_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,9 @@ object M {
7373
def test(input: => String): String = "foo " + input
7474
}
7575

76+
class S[X]
77+
object S { def show[X] = "dummyStr" }
78+
class T
79+
class U[Y](a: Y)
80+
def expects(take: (T) ?=> U[String]) = ???
81+

0 commit comments

Comments
 (0)