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

bypass constraints for tyFromExpr in generic bodies #23863

Merged
merged 1 commit into from
Jul 20, 2024

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Jul 20, 2024

fixes #19819, fixes #23339

Since #22029 tyFromExpr does not match anything in overloading, so generic bodies can know which call expressions to delay until the type can be evaluated. However generic type invocations also run overloading to check for generic constraints even in generic bodies. To prevent them from failing early from the overload not matching, pretend that tyFromExpr matches. This mirrors the behavior of the compiler in more basic cases like:

type
  Foo[T: int] = object
    x: T
  Bar[T] = object
    y: Foo[T]

Unfortunately this case doesn't respect the constraint (#21181, some other bugs) but tyFromExpr should easily use the same principle when it does.

@Araq Araq merged commit 31ee75f into nim-lang:devel Jul 20, 2024
18 checks passed
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 31ee75f

Hint: mm: orc; opt: speed; options: -d:release
173186 lines; 8.367s; 664.438MiB peakmem

narimiran pushed a commit that referenced this pull request Dec 16, 2024
fixes #19819, fixes #23339

Since #22029 `tyFromExpr` does not match anything in overloading, so
generic bodies can know which call expressions to delay until the type
can be evaluated. However generic type invocations also run overloading
to check for generic constraints even in generic bodies. To prevent them
from failing early from the overload not matching, pretend that
`tyFromExpr` matches. This mirrors the behavior of the compiler in more
basic cases like:

```nim
type
  Foo[T: int] = object
    x: T
  Bar[T] = object
    y: Foo[T]
```

Unfortunately this case doesn't respect the constraint (#21181, some
other bugs) but `tyFromExpr` should easily use the same principle when
it does.

(cherry picked from commit 31ee75f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants