Skip to content

Commit f8cd23f

Browse files
committed
Address remaining issues mentioned in the PR
1 parent a4da0f6 commit f8cd23f

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

shared/src/main/scala/mlscript/ucs/context/Context.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import pretyper.Scope
99

1010
class Context(originalTerm: If) {
1111
/** The prefix of all prefixes. */
12-
private val prefix = Context.freshPrefix()
12+
private val prefix = Context.freshPrefix
1313
private val cachePrefix = prefix + "$cache$"
1414
private val scrutineePrefix = prefix + "$scrut$"
1515
private val testPrefix = prefix + "$test$"
@@ -60,5 +60,5 @@ class Context(originalTerm: If) {
6060
}
6161

6262
object Context {
63-
private def freshPrefix(): Str = "ucs"
63+
private val freshPrefix: Str = "ucs"
6464
}

shared/src/main/scala/mlscript/ucs/stages/CoverageChecking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package ucs
33
package stages
44

55
import utils._, shorthands._, Message.MessageContext
6-
import ucs.context.{Context, Pattern, Scrutinee}
6+
import context.{Context, Pattern, Scrutinee}
77
import pretyper.Traceable, pretyper.symbol._
88

99
trait CoverageChecking { self: Desugarer with Traceable =>

shared/src/test/diff/pretyper/ucs/SpecilizationCollision.mls

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Derived(y: Int) extends Base(y + 1)
3838
//│ class Base(x: Int)
3939
//│ class Derived(y: Int) extends Base
4040

41-
:ducs:postprocess.result,coverage
41+
// Notice that Derived is not in the inferred type.
42+
:ducs:postprocess.result
4243
fun example3(t) =
4344
if t is
4445
Base(x) and p1(x) then x
@@ -60,42 +61,13 @@ fun example3(t) =
6061
//│ y
6162
//│ _ -> 42
6263
//│ _ -> 42
63-
//│ | | | | | | | STEP 4
64-
//│ | | | | | | | collected match registry:
65-
//│ | | | | | | | >>> t => [class `Base`, class `Derived`]
66-
//│ | | | | | | | >>> x => []
67-
//│ | | | | | | | >>> y => []
68-
//│ | | | | | | | checkCoverage <== 0 pending, 3 working, 0 seen
69-
//│ | | | | | | | | CASE t
70-
//│ | | | | | | | | SEEN: empty
71-
//│ | | | | | | | | class symbol: `Base`
72-
//│ | | | | | | | | REMOVE `Base` from working
73-
//│ | | | | | | | | unseen: [class `Base`, class `Derived`]
74-
//│ | | | | | | | | remaining: []
75-
//│ | | | | | | | | checkCoverage <== LET `ucs$args_t$Base`
76-
//│ | | | | | | | | checkCoverage <== LET `x`
77-
//│ | | | | | | | | checkCoverage <== LET `ucs$test$0`
78-
//│ | | | | | | | | checkCoverage <== TEST `ucs$test$0`
79-
//│ | | | | | | | | checkCoverage <== TERM x
80-
//│ | | | | | | | | checkCoverage <== 0 pending, 2 working, 1 seen
81-
//│ | | | | | | | | | CASE t
82-
//│ | | | | | | | | | SEEN: t is Base
83-
//│ | | | | | | | | | class symbol: `Derived`
84-
//│ | | | | | | | | | REMOVE `Derived` from working
85-
//│ | | | | | | | | | unseen: [class `Derived`]
86-
//│ | | | | | | | | | remaining: []
87-
//│ | | | | | | | | | checkCoverage <== LET `ucs$args_t$Derived`
88-
//│ | | | | | | | | | checkCoverage <== LET `y`
89-
//│ | | | | | | | | | checkCoverage <== TERM y
90-
//│ | | | | | | | | | remaining cases should be covered by the wildcard
91-
//│ | | | | | | | | | checkCoverage <== TERM 42
92-
//│ | | | | | | | | checkCoverage ==> 0 diagnostics
93-
//│ | | | | | | | | remaining cases should be covered by the wildcard
94-
//│ | | | | | | | | checkCoverage <== TERM 42
95-
//│ | | | | | | | checkCoverage ==> 0 diagnostics
96-
//│ | | | | | | | Coverage checking result: 0 errors
9764
//│ fun example3: forall 'a. (Base & {#x: Num & 'a} | Object & ~#Base) -> (Int | 'a)
9865

66+
example3(Derived(1))
67+
//│ Int
68+
//│ res
69+
//│ = 1
70+
9971
fun example4(t, x) =
10072
if t is
10173
Base(x) and p1(x) then x
@@ -119,3 +91,16 @@ example4(Derived(1), 4) ~~> 5
11991
//│ "passed"
12092
//│ res
12193
//│ = 'passed'
94+
95+
class Base(x: Int)
96+
class Derived[A](y: A) extends Base(1)
97+
//│ class Base(x: Int)
98+
//│ class Derived[A](y: A) extends Base
99+
100+
// Notice that now Derived is generic, so it's appear in the inferred type.
101+
fun example5(t) =
102+
if t is
103+
Base(x) and p1(x) then x
104+
Derived(y) then y
105+
else 42
106+
//│ fun example5: forall 'a 'b. (Base & {#x: Num & 'a} & ~#Derived | Derived['b] & {#x: Num & 'a} | Object & ~#Base) -> (42 | 'a | 'b)

0 commit comments

Comments
 (0)