Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Lean/Compiler/LCNF/ToDecl.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Lean.Compiler.Options
import Lean.Meta.Transform
import Lean.Meta.Match.MatcherInfo
import Init.While
import Lean.Compiler.ExportAttr

public section

Expand Down Expand Up @@ -169,6 +170,8 @@ def toDecl (declName : Name) : CompilerM (Decl .pure) := do
decl ← decl.etaExpand
if compiler.ignoreBorrowAnnotation.get (← getOptions) then
decl := { decl with params := ← decl.params.mapM (·.updateBorrow false) }
if isExport env decl.name && decl.params.any (·.borrow) then
throwError m!" Declaration {decl.name} is marked as `export` but some of its parameters have borrow annotations.\n Consider using `set_option compiler.ignoreBorrowAnnotation true in` to supress the borrow annotations in its type.\n If the declaration is part of an `export`/`extern` pair make sure to also supress the annotations at the `extern` declaration."
return decl

end Lean.Compiler.LCNF
2 changes: 1 addition & 1 deletion src/Lean/LoadDynlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ If multiple libraries share common symbols, those symbols should be linked
and loaded as separate libraries.
-/
@[export lean_load_dynlib]
def loadDynlib (path : @& System.FilePath) : IO Unit := do
def loadDynlib (path : System.FilePath) : IO Unit := do
let dynlib ← Dynlib.load path
-- Lean never unloads libraries.
-- Safety: There are no concurrent accesses to `dynlib` at this point.
Expand Down
12 changes: 12 additions & 0 deletions tests/elab/lcnf_export_borrow_error.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module

/-! Assert that putting a borrow annotation on an export errors -/

/--
error: Declaration bar is marked as `export` but some of its parameters have borrow annotations.
Consider using `set_option compiler.ignoreBorrowAnnotation true in` to supress the borrow annotations in its type.
If the declaration is part of an `export`/`extern` pair make sure to also supress the annotations at the `extern` declaration.
-/
#guard_msgs in
@[export foo]
public def bar (x : @& String) := x
Loading