Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type of attrset from function application in let-binding is not propagated to usage in the let body #105

Open
cassandracomar opened this issue Sep 6, 2023 · 1 comment
Labels
A-ty Area: type system

Comments

@cassandracomar
Copy link

simple example:

{ stdenv, ... }:
let
  archComponentsFor = system: {
    "aarch64-darwin" = {
      arch = "arm64";
      os = "darwin";
      sha256 = "3c1e8b95cef4ff6e52d5f4b8c65b8d9d06b75f42d1cb40986c1d67729d82411a";
    };
  }.${system};
  # components is correctly recognized here:
  # Let binding components
  # { arch: string, os: string, sha256: ? 
  components = archComponentsFor stdenv.system;

in {
 # components is not correctly recognized here:
 # Let binding components
 # ?
  test = components.|
}

consequently, no completions are available inside the let body until the fields are used. I'm also not sure why the sha256 attribute has type ? when it's set to a string, but that's not really that big of a deal as it's a simple value.

@oxalica oxalica added the A-ty Area: type system label Sep 8, 2023
@oxalica
Copy link
Owner

oxalica commented Sep 8, 2023

The inference fails for the dynamic attribute {..}.${system} when system is not a string literal. components in your example has type ? for me. The hint you see may result from inferences from your other piece of code.

Your case has only a single attribute in that attrset. But for { a = { foo = 1; }; b = { bar = 2; }; }.${system}, I'm not sure what type should it have. Probably a union of all field types { foo?: int, bar?: int }? It may be huge and costly for already-huge attrsets like pkgs, and may not help much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty Area: type system
Projects
None yet
Development

No branches or pull requests

2 participants