Skip to content

Commit

Permalink
nixd/Sema: lowering for ExprAssert & ExprWith
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 18, 2023
1 parent 9947e27 commit 9e3cc38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions nixd/lib/Sema/Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "nixd/Sema/EvalContext.h"
#include "nixd/Syntax/Diagnostic.h"
#include "nixd/Syntax/Nodes.h"
#include "nixexpr.hh"

namespace nixd {

Expand Down Expand Up @@ -122,6 +123,22 @@ nix::Expr *Lowering::lower(EvalContext &Ctx, nixd::syntax::Node *Root) {
auto *Fn = dynamic_cast<syntax::Function *>(Root);
return lowerFunction(Ctx, Fn);
}
case Node::NK_Assert: {
auto *Assert = dynamic_cast<syntax::Assert *>(Root);
auto *Cond = lower(Ctx, Assert->Cond);
auto *Body = lower(Ctx, Assert->Body);
auto *NixAssert =
Ctx.Pool.record(new nix::ExprAssert(Assert->Range.Begin, Cond, Body));
return NixAssert;
}
case Node::NK_With: {
auto *With = dynamic_cast<syntax::With *>(Root);
auto *Attrs = lower(Ctx, With->Attrs);
auto *Body = lower(Ctx, With->Body);
auto *NixWith =
Ctx.Pool.record(new nix::ExprWith(With->Range.Begin, Attrs, Body));
return NixWith;
}
}

return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions nixd/tools/nixd-lint/test/lowering-assert.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# RUN: nixd-lint %s | FileCheck %s

# CHECK: function argument duplicated to a function formal
assert 0; a @ { a }: 1
4 changes: 4 additions & 0 deletions nixd/tools/nixd-lint/test/lowering-with.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# RUN: nixd-lint %s | FileCheck %s

# CHECK: function argument duplicated to a function formal
with 1; { a } @ a : 1

0 comments on commit 9e3cc38

Please sign in to comment.