You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: grin/test/LintSpec.hs
+18-23Lines changed: 18 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -224,45 +224,40 @@ spec = do
224
224
let (_, errors) = lint allWarnings (Just typeEnv) program
225
225
lintErrors errors `shouldBe` ["Invalid pattern match for (CInt x). Expected pattern of type: {CInt[T_Dead]}, but got: {CFloat[T_Float]}"]
226
226
227
-
it "disregards variable patterns"$do
227
+
it "doesn't alert over-approximated binds"$do
228
228
let program = [prog|
229
229
main =
230
-
n0 <- pure (CInt 0)
231
-
n1 <- case n0 of
232
-
(CInt c0) -> pure n0
233
-
(CFloat c1) ->
234
-
a0 <- pure (CFloat 2.0)
235
-
pure a0
230
+
i <- pure (CInt 1)
231
+
f <- pure (CFloat 1.0)
232
+
l <- store i
233
+
update l f
234
+
v <- fetch l
235
+
(CFloat f2) <- pure v
236
236
pure ()
237
237
|]
238
238
let typeEnv = inferTypeEnv program
239
239
let (_, errors) = lint allWarnings (Just typeEnv) program
240
240
lintErrors errors `shouldBe`[]
241
241
242
-
-- NOTE: Bottom-up typing can only approximate the result of HPT.
243
-
it "can give false positive errors"$do
242
+
it "disregards variable patterns"$do
244
243
let program = [prog|
245
244
main =
246
-
n0 <- case 0 of
247
-
0 ->
248
-
n1 <- pure (CInt 0)
249
-
pure n1
250
-
1 ->
251
-
n2 <- pure (CFloat 0.0)
252
-
pure n2
253
-
(CInt x) <- case n0 of
245
+
k0 <- pure 0
246
+
n0 <- pure (CInt k0)
247
+
n1 <- case n0 of
254
248
(CInt c0) -> pure n0
255
249
(CFloat c1) ->
256
-
a0 <- pure (CInt 0)
250
+
k1 <- pure 2.0
251
+
a0 <- pure (CFloat k1)
257
252
pure a0
258
253
pure ()
259
254
|]
260
255
let typeEnv = inferTypeEnv program
261
256
let (_, errors) = lint allWarnings (Just typeEnv) program
262
-
lintErrors errors `shouldBe` ["Invalid pattern match for (CInt x). Expected pattern of type: {CInt[T_Int64]}, but got: {CFloat[T_Float],CInt[T_Int64]}"]
257
+
lintErrors errors `shouldBe`[]
263
258
264
259
describe "Producer lint"$do
265
-
it "finds nodes in single return statment"$do
260
+
it "finds nodes in single return statement"$do
266
261
let program = [prog|
267
262
grinMain =
268
263
pure (CInt 5)
@@ -271,7 +266,7 @@ spec = do
271
266
let (_, errors) = lint allWarnings (Just typeEnv) program
272
267
lintErrors errors `shouldBe` ["Last return expressions can only return non-node values: pure (CInt 5)"]
273
268
274
-
it "finds nodes in last return statment"$do
269
+
it "finds nodes in last return statement"$do
275
270
let program = [prog|
276
271
grinMain =
277
272
n <- pure (CInt 0)
@@ -281,7 +276,7 @@ spec = do
281
276
let (_, errors) = lint allWarnings (Just typeEnv) program
282
277
lintErrors errors `shouldBe` ["Last return expressions can only return non-node values: pure (CInt 5)"]
283
278
284
-
it "finds nodes in single return statment in case alternative"$do
279
+
it "finds nodes in single return statement in case alternative"$do
285
280
let program = [prog|
286
281
grinMain =
287
282
case 0 of
@@ -291,7 +286,7 @@ spec = do
291
286
let (_, errors) = lint allWarnings (Just typeEnv) program
292
287
lintErrors errors `shouldBe` ["Last return expressions can only return non-node values: pure (CInt 5)"]
293
288
294
-
it "finds nodes in last return statment in case alternative"$do
289
+
it "finds nodes in last return statement in case alternative"$do
0 commit comments