Skip to content

Commit 2f3d33f

Browse files
committed
Did I find a compiler bug...?
1 parent 59281aa commit 2f3d33f

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ optValues = do
118118
logShow $ consumer { a: "test", b, c: { d: { e: { g, h: "test" }}}}
119119
```
120120

121+
Library provides some debug info which should help when there is a type mismatch.
122+
123+
```purescript
124+
type NestedError =
125+
{ l :: Array { x :: Opt Int, y :: Int, z :: Opt (Array Int)}}
126+
127+
x = (coerce { l: [{ y: 9, z: [] }]}) :: NestedError
128+
```
129+
130+
we can get quite informative error message with property path like:
131+
132+
```shell
133+
Type mismatch on the path: { l."Array".z."Array" }. Expecting
134+
135+
Int
136+
137+
but got
138+
139+
String
140+
```
121141
122142
## Limitiation
123143

src/Data/Undefined/NoProblem.purs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ instance coercePropsNil
5757
CoerceProps Nil Nil any
5858

5959
else instance coercePropsCons
60-
∷ (CoerceProp a b (n ::: debugPath))
60+
∷ (CoerceProp a b (n ::: debugPath), CoerceProps t t' debugPath)
6161
CoerceProps (Cons n a t) (Cons n b t') debugPath
6262

6363
-- | Handle missing field using Opt
@@ -108,15 +108,18 @@ class CoerceProp given expected (debugPath ∷ SList) | expected → debugPath
108108
-- -- |
109109
-- -- | The rest is handling errors and providing intances
110110
-- -- | for well known polymorphic types like `Maybe`, `Either`...
111-
instance coercePropOptValue
111+
instance coercePropOptValues
112112
∷ (CoerceProp a b p)
113113
CoerceProp (Opt a) (Opt b) p
114-
else instance coercePropValue
114+
else instance coercePropOptValue
115115
∷ (CoerceProp a b p)
116116
CoerceProp a (Opt b) p
117117
else instance coercePropRecord
118-
∷ (RowToList e el, RowToList g gl, CoerceProps el gl p)
119-
CoerceProp { | e } { | g } p
118+
∷ (RowToList e el, RowToList g gl, CoerceProps gl el p)
119+
CoerceProp { | g } { | e } p
120+
121+
else instance coercePropMatch
122+
:: CoerceProp a a p
120123

121124
-- | These instances are provided to allow coercing over popular types
122125

@@ -146,37 +149,33 @@ else instance coercePropEffect
146149

147150
-- | These instances are provided only for nice debuging experience.
148151

149-
else instance coercePropStringMatchCoerceProp String String p
150-
else instance coercePropStringGivenMismatch
151-
∷ (RenderPath p p', TypeMismatchErr String a p msg, Fail msg)
152-
CoerceProp String a p
153-
else instance coercePropStringExpectedMismatch
154-
∷ (RenderPath p p', TypeMismatchErr String a p msg, Fail msg)
155-
CoerceProp a String p
156-
157-
else instance coercePropIntMatchCoerceProp Int Int p
158-
else instance coercePropIntGivenMismatch
159-
∷ (RenderPath p p', TypeMismatchErr Int a p msg, Fail msg)
160-
CoerceProp Int a p
161152
else instance coercePropIntExpectedMismatch
162153
∷ (RenderPath p p', TypeMismatchErr a Int p msg, Fail msg)
163154
CoerceProp a Int p
155+
else instance coercePropIntGivenMismatch
156+
∷ (RenderPath p p', TypeMismatchErr Int a p msg, Fail msg)
157+
CoerceProp Int a p
158+
159+
else instance coercePropStringExpectedMismatch
160+
∷ (RenderPath p p', TypeMismatchErr a String p msg, Fail msg)
161+
CoerceProp a String p
162+
else instance coercePropStringGivenMismatch
163+
∷ (RenderPath p p', TypeMismatchErr String a p msg, Fail msg)
164+
CoerceProp String a p
164165

165-
else instance coercePropNumberMatchCoerceProp Number Number p
166-
else instance coercePropNumberGivenMismatch
167-
∷ (RenderPath p p', TypeMismatchErr Number a p msg, Fail msg)
168-
CoerceProp Number a p
169166
else instance coercePropNumberExpectedMismatch
170167
∷ (RenderPath p p', TypeMismatchErr a Number p msg, Fail msg)
171168
CoerceProp a Number p
169+
else instance coercePropNumberGivenMismatch
170+
∷ (RenderPath p p', TypeMismatchErr Number a p msg, Fail msg)
171+
CoerceProp Number a p
172172

173-
else instance coercePropBooleanMatchCoerceProp Boolean Boolean p
174-
else instance coercePropBooleanGivenMismatch
175-
∷ (RenderPath p p', TypeMismatchErr Boolean a p msg, Fail msg)
176-
CoerceProp Boolean a p
177173
else instance coercePropBooleanExpectedMismatch
178174
∷ (RenderPath p p', TypeMismatchErr a Boolean p msg, Fail msg)
179175
CoerceProp a Boolean p
176+
else instance coercePropBooleanGivenMismatch
177+
∷ (RenderPath p p', TypeMismatchErr Boolean a p msg, Fail msg)
178+
CoerceProp Boolean a p
180179

181180
-- else instance coercePropPoly ∷ CoerceProp a b b p
182181

0 commit comments

Comments
 (0)