File tree Expand file tree Collapse file tree 5 files changed +24
-7
lines changed
output/test/test-for-errors Expand file tree Collapse file tree 5 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 1- (defn my-curry [f] (fn [x] (fn [y] (f x y))))
2- (defn double-curry [f] (fn [x] (fn [y] (fn [z] (f x y z)))))
1+ (defn my-curry [f] (fn [x] (fn [y] (~ f x y))))
2+ (defn double-curry [f] (fn [x] (fn [y] (fn [z] (~ f x y z)))))
33
44(defn make-cb []
55 ((fn []
1515(defn main []
1616 (do ((make-cb))
1717 ((make-cb2))
18- (((my-curry (fn [x y] (Int.+ x y))) 1) 2)))
18+ (((my-curry & (fn [x y] (Int.+ x y))) 1) 2)))
Original file line number Diff line number Diff line change @@ -524,10 +524,13 @@ unmanage typeEnv globalEnv xobj =
524524 then Left (UsingCapturedValue xobj)
525525 else Left (UsingUnownedValue xobj)
526526 [one] ->
527- let newDeleters = Set. delete one (memStateDeleters m)
528- in do
529- put $ m {memStateDeleters = newDeleters}
530- pure (Right () )
527+ if isSymbolThatCaptures xobj
528+ then pure (Left (GivingAwayCapturedValue xobj))
529+ else
530+ let newDeleters = Set. delete one (memStateDeleters m)
531+ in do
532+ put $ m {memStateDeleters = newDeleters}
533+ pure (Right () )
531534 tooMany -> error (" Too many variables with the same name in set: " ++ show tooMany)
532535 else pure (Right () )
533536
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ data TypeError
6464 | FailedToAddLambdaStructToTyEnv SymPath XObj
6565 | FailedToInstantiateGenericType Ty
6666 | InvalidStructField XObj
67+ | GivingAwayCapturedValue XObj
6768
6869instance Show TypeError where
6970 show (SymbolMissingType xobj env) =
@@ -334,6 +335,9 @@ instance Show TypeError where
334335 ++ " to the type environment."
335336 show (FailedToInstantiateGenericType ty) =
336337 " I couldn't instantiate the generic type " ++ show ty
338+ show (GivingAwayCapturedValue xobj) =
339+ " Can't give away the captured value '" ++ pretty xobj ++ " ' at " ++ prettyInfoFromXObj xobj
340+ ++ " . Captured values can be borrowed with `&` or copied with `@&`, not moved."
337341
338342machineReadableErrorStrings :: FilePathPrintLength -> TypeError -> [String ]
339343machineReadableErrorStrings fppl err =
@@ -460,6 +464,8 @@ machineReadableErrorStrings fppl err =
460464 ++ pretty xobj
461465 ++ " to the type environment."
462466 ]
467+ (GivingAwayCapturedValue xobj) ->
468+ [machineReadableInfoFromXObj fppl xobj ++ " Can't give away captured value '" ++ pretty xobj ++ " '." ]
463469 _ ->
464470 [show err]
465471
Original file line number Diff line number Diff line change 1+ lambda_leaking_capture.carp:6:18 Can't give away captured value 's'.
Original file line number Diff line number Diff line change 1+ (Project.config "file-path-print-length" "short")
2+
3+ ;; see [issue #1040](https://github.com/carp-lang/Carp/issues/1040)
4+ (defn lambda-leak []
5+ (let [s @""
6+ f (fn [] s)]
7+ (ignore (f))))
You can’t perform that action at this time.
0 commit comments