Skip to content

Commit 4a91353

Browse files
committed
Fix findFunctionType for OrTypes
Restore funtionality that was dropped in 6ac8b47 Fixes #15460
1 parent f58c158 commit 4a91353

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,14 +1690,20 @@ object Types {
16901690
* is returned. If no function type is found, Any is returned.
16911691
*/
16921692
def findFunctionType(using Context): Type = dealias match
1693-
case tp: AndOrType =>
1693+
case tp: AndType =>
16941694
tp.tp1.findFunctionType & tp.tp2.findFunctionType
1695+
case tp: OrType =>
1696+
val tf1 = tp.tp1.findFunctionType
1697+
val tf2 = tp.tp2.findFunctionType
1698+
if !tf1.exists then tf2
1699+
else if !tf2.exists then tf1
1700+
else NoType
16951701
case t if defn.isNonRefinedFunction(t) =>
16961702
t
16971703
case t @ SAMType(_) =>
16981704
t
16991705
case _ =>
1700-
defn.AnyType
1706+
NoType
17011707

17021708
/** This type seen as a TypeBounds */
17031709
final def bounds(using Context): TypeBounds = this match {

tests/pos/i15460.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type C = (() => Int) | (() => String)
2+
3+
def foo(c: C): Unit = ()
4+
5+
val _ = foo(() => 1)

0 commit comments

Comments
 (0)