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
+16-23Lines changed: 16 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -224,45 +224,38 @@ 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
+
n0 <- pure (CInt 0)
246
+
n1 <- case n0 of
254
247
(CInt c0) -> pure n0
255
248
(CFloat c1) ->
256
-
a0 <- pure (CInt 0)
249
+
a0 <- pure (CFloat 2.0)
257
250
pure a0
258
251
pure ()
259
252
|]
260
253
let typeEnv = inferTypeEnv program
261
254
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]}"]
255
+
lintErrors errors `shouldBe`[]
263
256
264
257
describe "Producer lint"$do
265
-
it "finds nodes in single return statment"$do
258
+
it "finds nodes in single return statement"$do
266
259
let program = [prog|
267
260
grinMain =
268
261
pure (CInt 5)
@@ -271,7 +264,7 @@ spec = do
271
264
let (_, errors) = lint allWarnings (Just typeEnv) program
272
265
lintErrors errors `shouldBe` ["Last return expressions can only return non-node values: pure (CInt 5)"]
273
266
274
-
it "finds nodes in last return statment"$do
267
+
it "finds nodes in last return statement"$do
275
268
let program = [prog|
276
269
grinMain =
277
270
n <- pure (CInt 0)
@@ -281,7 +274,7 @@ spec = do
281
274
let (_, errors) = lint allWarnings (Just typeEnv) program
282
275
lintErrors errors `shouldBe` ["Last return expressions can only return non-node values: pure (CInt 5)"]
283
276
284
-
it "finds nodes in single return statment in case alternative"$do
277
+
it "finds nodes in single return statement in case alternative"$do
285
278
let program = [prog|
286
279
grinMain =
287
280
case 0 of
@@ -291,7 +284,7 @@ spec = do
291
284
let (_, errors) = lint allWarnings (Just typeEnv) program
292
285
lintErrors errors `shouldBe` ["Last return expressions can only return non-node values: pure (CInt 5)"]
293
286
294
-
it "finds nodes in last return statment in case alternative"$do
287
+
it "finds nodes in last return statement in case alternative"$do
0 commit comments