Skip to content

Commit 31b364e

Browse files
committed
fix test: single function in overload
1 parent d40c9b7 commit 31b364e

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

shared/src/main/scala/mlscript/TyperDatatypes.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,17 @@ abstract class TyperDatatypes extends TyperHelpers { Typer: Typer =>
744744
}
745745
def mk(ov: Overload)(implicit lvl: Level): FunctionType = {
746746
def unwrap(t: ST): ST = t.map(unwrap)
747-
val f = ov.mapAlts(unwrap)(unwrap)
748-
val (t, tvs, constrs) = lcgFunction(f.alts.head, f.alts.tail)(ov.prov, lvl)
749-
val tsc = new TupleSetConstraints(MutSet.empty ++ constrs.transpose, tvs)(ov.prov)
750-
tvs.zipWithIndex.foreach { case (tv, i) =>
751-
tv.lbtsc = S((tsc, i))
752-
tv.ubtsc = S((tsc, i))
747+
if (ov.alts.tail.isEmpty) ov.alts.head else {
748+
val f = ov.mapAlts(unwrap)(unwrap)
749+
val (t, tvs, constrs) = lcgFunction(f.alts.head, f.alts.tail)(ov.prov, lvl)
750+
val tsc = new TupleSetConstraints(MutSet.empty ++ constrs.transpose, tvs)(ov.prov)
751+
tvs.zipWithIndex.foreach { case (tv, i) =>
752+
tv.lbtsc = S((tsc, i))
753+
tv.ubtsc = S((tsc, i))
754+
}
755+
println(s"TSC mk: ${tsc.tvs} in ${tsc.constraints}")
756+
t
753757
}
754-
println(s"TSC mk: ${tsc.tvs} in ${tsc.constraints}")
755-
t
756758
}
757759
}
758760
}

shared/src/main/scala/mlscript/TyperHelpers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,15 +983,15 @@ abstract class TyperHelpers { Typer: Typer =>
983983
def getVars: SortedSet[TypeVariable] = getVarsImpl(includeBounds = true)
984984

985985
def showBounds: String =
986-
getVars.iterator.filter(tv => tv.assignedTo.nonEmpty || (tv.upperBounds ++ tv.lowerBounds).nonEmpty || (tv.lbtsc.fold(false)(!_._1.tvs.contains(tv)))).map {
986+
getVars.iterator.filter(tv => tv.assignedTo.nonEmpty || (tv.upperBounds ++ tv.lowerBounds).nonEmpty || (tv.lbtsc.isDefined && tv.ubtsc.isEmpty)).map {
987987
case tv @ AssignedVariable(ty) => "\n\t\t" + tv.toString + " := " + ty
988988
case tv => ("\n\t\t" + tv.toString
989989
+ (if (tv.lowerBounds.isEmpty) "" else " :> " + tv.lowerBounds.mkString(" | "))
990990
+ (if (tv.upperBounds.isEmpty) "" else " <: " + tv.upperBounds.mkString(" & "))
991991
+ tv.lbtsc.fold(""){ case (tsc, i) => " :> " + tsc.tvs(i) } )
992992
}.mkString + {
993993
val visited: MutSet[TV] = MutSet.empty
994-
getVars.iterator.filter(tv => tv.lbtsc.fold(false)(_._1.tvs.contains(tv))).map {
994+
getVars.iterator.filter(tv => tv.ubtsc.isDefined).map {
995995
case tv if visited.contains(tv) => ""
996996
case tv =>
997997
visited ++= tv.lbtsc.fold(Nil: Ls[TV])(_._1.tvs)

shared/src/test/diff/nu/ArrayProg.mls

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ fun s: (([Numbr,Numbr] -> Int) & ([Vectr,Vectr] -> Int),)
136136
fun s: ([Numbr,Numbr] -> Int) & ([Vectr,Vectr] -> Int)
137137
//│ fun s: (Numbr | Vectr, Numbr | Vectr) -> Int
138138

139-
140139
s(Vectr([]),Vectr([]))
141140
//│ Int
142141
//│ res
@@ -155,7 +154,7 @@ module A {
155154
//│ }
156155

157156
A.g(0)
158-
//│ Int | Str
157+
//│ Int
159158
//│ res
160159
//│ = 0
161160

shared/src/test/diff/nu/WeirdUnions.mls

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ fun f: (Str => Str) & ((Str, Int) => Int)
4747
//│ fun f: Str -> Str & (Str, Int) -> Int
4848

4949
// * ...resulting in approximation at call sites (we don't handle overloading)
50+
:e // TODO
5051
f("abc", "abc")
51-
//│ Int | Str
52+
//│ ╔══[ERROR] Type mismatch in application:
53+
//│ ║ l.51: f("abc", "abc")
54+
//│ ║ ^^^^^^^^^^^^^^^
55+
//│ ╟── argument list of type `["abc", "abc"]` does not match type `?a`
56+
//│ ║ l.51: f("abc", "abc")
57+
//│ ║ ^^^^^^^^^^^^^^
58+
//│ ╟── Note: constraint arises from function type:
59+
//│ ║ l.46: fun f: (Str => Str) & ((Str, Int) => Int)
60+
//│ ╙── ^^^^^^^^^^^^^^^^^^^
61+
//│ error
5262
//│ res
5363
//│ = <no result>
5464
//│ f is not implemented
5565

5666
f("abcabc")
57-
//│ Int | Str
67+
//│ Str
5868
//│ res
5969
//│ = <no result>
6070
//│ f is not implemented
@@ -71,19 +81,19 @@ let r = if true then id else (x, y) => [y, x]
7181
r(error)
7282
r(error, error)
7383
//│ ╔══[ERROR] Type mismatch in application:
74-
//│ ║ l.71: r(error)
84+
//│ ║ l.81: r(error)
7585
//│ ║ ^^^^^^^^
7686
//│ ╟── argument of type `[nothing]` does not match type `[?a, ?b]`
77-
//│ ║ l.71: r(error)
87+
//│ ║ l.81: r(error)
7888
//│ ║ ^^^^^^^
7989
//│ ╟── Note: constraint arises from tuple literal:
80-
//│ ║ l.65: let r = if true then id else (x, y) => [y, x]
90+
//│ ║ l.75: let r = if true then id else (x, y) => [y, x]
8191
//│ ╙── ^^^^
8292
//│ ╔══[ERROR] Type mismatch in application:
83-
//│ ║ l.72: r(error, error)
93+
//│ ║ l.82: r(error, error)
8494
//│ ║ ^^^^^^^^^^^^^^^
8595
//│ ╟── argument list of type `[nothing, nothing]` does not match type `[?a]`
86-
//│ ║ l.72: r(error, error)
96+
//│ ║ l.82: r(error, error)
8797
//│ ╙── ^^^^^^^^^^^^^^
8898
//│ error | [nothing, nothing]
8999
//│ res
@@ -106,7 +116,7 @@ r of [0, 1]
106116

107117
// Also currently parses the same:
108118
let r = if true then id else [x, y] => [y, x]
109-
//│ let r: forall 'a 'b 'c. (['b, 'c] & 'a) -> (['c, 'b] | 'a)
119+
//│ let r: forall 'a 'b 'c. (['a, 'b] & 'c) -> (['b, 'a] | 'c)
110120
//│ r
111121
//│ = [Function: id]
112122

0 commit comments

Comments
 (0)