Skip to content

Conversation

@abs0luty
Copy link
Contributor

@abs0luty abs0luty commented Oct 24, 2025

@abs0luty abs0luty changed the title Preserve generic type parameters when constructors or functions are used without explicit annotations Preserve generic type parameters when constructors, functions are used without explicit annotations Oct 24, 2025
@abs0luty abs0luty changed the title Preserve generic type parameters when constructors, functions are used without explicit annotations Preserve generic parameters when constructors, functions are used without explicit annotations Oct 24, 2025
@abs0luty abs0luty force-pushed the fix-type-inference branch 2 times, most recently from 96d4132 to 980e01e Compare October 24, 2025 17:37
@abs0luty abs0luty changed the title Preserve generic parameters when constructors, functions are used without explicit annotations Fix type inference for functions, constructors without explicit annotations. Oct 24, 2025
@abs0luty abs0luty changed the title Fix type inference for functions, constructors without explicit annotations. Fix type inference for functions, constructors without explicit annotations Oct 24, 2025
@abs0luty abs0luty force-pushed the fix-type-inference branch 3 times, most recently from 0761e59 to d1a7ec5 Compare October 31, 2025 06:19
@abs0luty abs0luty changed the title Fix type inference for functions, constructors without explicit annotations Fix generic inference by instantiating annotations and storing inferred types Nov 24, 2025
…ns before unification

```gleam
pub type Test(a) { Test(a) }
pub fn it(value: Test(a)) { it2(value) }
pub fn it2(value: Test(a)) -> Test(a) { it(value) }

pub fn main() { it(Test(1)) }
```

Before this change the compiler compared generic "sketches" directly to inferred types
in mutually recursive calls, causing false mismatches when generics behaved rigidly.

After the patch the compiler instantiates generics (based on annotations or inferred
concrete types) and updates the environment so mutually recursive functions unify correctly.

This resolves spurious type-errors in recursive scenarios.
@abs0luty abs0luty changed the title Fix generic inference by instantiating annotations and storing inferred types Instantiate generics in mutually recursive functions before unification Dec 3, 2025
```
fn wibble(a, b, c) {
   ↑
  let x: a = todo
  fn(a: b, b: c) -> d {
    todo
  }
}
```

After action:
```diff
- fn wibble(a: e, b: f, c: g) -> fn(b, c) -> h
+ fn wibble(a: e, b: f, c: g) -> fn(b, c) -> d
                                             ^ original name is preserved
```

When the "add annotations" code-action is used, the compiler now retains the
original type-variable names from the user's annotation instead of replacing them
with fresh or default names.

This ensures that added annotations reflect the user's naming exactly and prevents
confusing or misleading variable renaming.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants