# compiler: treat decl_val/decl_ref of potentially generic decls as captures · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/2c4ac44f25743f5b7ae9db6bc570ab71f15fd83b)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 2c4ac44f25743f5b7ae9db6bc570ab71f15fd83b

Requested commit: 2c4ac44f25743f5b7ae9db6bc570ab71f15fd83b

Commit: 2c4ac44f25743f5b7ae9db6bc570ab71f15fd83b

Tree: 5936a2c47c13ea1fcd5bd37ce523754517be38cf

Author: mlugg

Committer: mlugg

## Message

````
compiler: treat decl_val/decl_ref of potentially generic decls as captures

This fixes an issue with the implementation of #18816. Consider the
following code:

```zig
pub fn Wrap(comptime T: type) type {
    return struct {
        pub const T1 = T;
        inner: struct { x: T1 },
    };
}
```

Previously, the type of `inner` was not considered to be "capturing" any
value, as `T1` is a decl. However, since it is declared within a generic
function, this decl reference depends on the context, and thus should be
treated as a capture.

AstGen has been augmented to tunnel references to decls through closure
when the decl was declared in a potentially-generic context (i.e. within
a function).

````

## Parents

- [d0c022f7347b5cda34751a986a535aee3b1f45dc](https://git.cafe/gitcafe/zig/commit/d0c022f7347b5cda34751a986a535aee3b1f45dc?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/2c4ac44f25743f5b7ae9db6bc570ab71f15fd83b?format=markdown)
