checker: allow for const source = $embed_file(@FILE).to_string()

This commit is contained in:
Delyan Angelov 2023-09-30 08:50:02 +03:00
parent ae5b4bbd17
commit ced5f213ef
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 13 additions and 0 deletions

View file

@ -71,6 +71,11 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
if node.args.len == 1 { if node.args.len == 1 {
embed_arg := node.args[0] embed_arg := node.args[0]
mut raw_path := '' mut raw_path := ''
if embed_arg.expr is ast.AtExpr {
mut expr := embed_arg.expr
c.at_expr(mut expr)
raw_path = expr.val
}
if embed_arg.expr is ast.StringLiteral { if embed_arg.expr is ast.StringLiteral {
raw_path = embed_arg.expr.val raw_path = embed_arg.expr.val
} else if embed_arg.expr is ast.Ident { } else if embed_arg.expr is ast.Ident {

View file

@ -0,0 +1,8 @@
const self_file = $embed_file(@FILE)
fn test_self_file() {
source := self_file.to_string()
assert source.contains('self_file.to_string')
assert source.contains('fn test_self_file() {')
assert source.split_into_lines().len > @LINE.int()
}