File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,16 @@ julia> redirect_stdout(devnull) do
96
96
```
97
97
"""
98
98
function trixi_include (mod:: Module , example:: AbstractString ; kwargs... )
99
+ # Check that all kwargs exist as assignments
100
+ code = read (example, String)
101
+ expr = Meta. parse (" begin \n $code \n end" )
102
+ expr = insert_maxiters (expr)
103
+
104
+ for (key, val) in kwargs
105
+ # This will throw an error when `key` is not found
106
+ find_assignment (expr, key)
107
+ end
108
+
99
109
Base. include (ex -> replace_assignments (insert_maxiters (ex); kwargs... ), mod, example)
100
110
end
101
111
@@ -282,19 +292,25 @@ end
282
292
function find_assignment (expr, destination)
283
293
# declare result to be able to assign to it in the closure
284
294
local result
295
+ found = false
285
296
286
297
# find explicit and keyword assignments
287
298
walkexpr (expr) do x
288
299
if x isa Expr
289
300
if (x. head === Symbol (" =" ) || x. head === :kw ) &&
290
301
x. args[1 ] === Symbol (destination)
291
302
result = x. args[2 ]
303
+ found = true
292
304
# dump(x)
293
305
end
294
306
end
295
307
return x
296
308
end
297
309
310
+ if ! found
311
+ throw (ArgumentError (" assignment `$destination ` not found in expression" ))
312
+ end
313
+
298
314
result
299
315
end
300
316
You can’t perform that action at this time.
0 commit comments