summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorJake Leahy <jake@leahy.dev>2022-12-16 05:22:45 +1100
committerGitHub <noreply@github.com>2022-12-15 19:22:45 +0100
commitd00477dffb2c62732b87a440c61706de5b480f48 (patch)
tree66a4e5fa32e50df2e35732e8b0988d822e5053c8 /compiler
parent8054be6e529db9e65a18e4c4a37ec54f64f9121c (diff)
downloadNim-d00477dffb2c62732b87a440c61706de5b480f48.tar.gz
Check file exists in `{.compile.}` pragma (#21105)
* Add test

* Check file exists before adding it into compilation

* Make error message look like other error messages

i.e. following the format `error msg: file`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/pragmas.nim7
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 993e6edce..92e3d1922 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -513,8 +513,11 @@ proc processCompile(c: PContext, n: PNode) =
     var cf = Cfile(nimname: splitFile(src).name,
                    cname: src, obj: dest, flags: {CfileFlag.External},
                    customArgs: customArgs)
-    extccomp.addExternalFileToCompile(c.config, cf)
-    recordPragma(c, it, "compile", src.string, dest.string, customArgs)
+    if not fileExists(src):
+      localError(c.config, n.info, "cannot find: " & src.string)
+    else:
+      extccomp.addExternalFileToCompile(c.config, cf)
+      recordPragma(c, it, "compile", src.string, dest.string, customArgs)
 
   proc getStrLit(c: PContext, n: PNode; i: int): string =
     n[i] = c.semConstExpr(c, n[i])