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

Let inferGenericTypes continue if a param is already bound #22384

Merged
merged 11 commits into from
Aug 6, 2023

Conversation

SirOlaf
Copy link
Contributor

@SirOlaf SirOlaf commented Aug 4, 2023

The current inference does not support code like below as T or E will be bound already which causes an early return. Originally this PR was gonna try to convert the types for string to cstring conversion, but that causes more problems than it solves, so now it simply lets the inference continue instead of returning.

{.experimental: "inferGenericTypes".}

type
  ResultKind = enum
    Ok, Error

  Result[T, E] = object
    case kind: ResultKind
    of Ok:
      okVal: T
    of Error:
      errVal: E

proc ok[T, E](x: T): Result[T, E] =
  Result[T, E](kind : Ok, okVal : x)

proc err[T, E](x: E): Result[T, E] =
  Result[T, E](kind : Error, errVal : x)

proc doStuff(): Result[int, string] = 
  err("Error")

@SirOlaf
Copy link
Contributor Author

SirOlaf commented Aug 5, 2023

The conversion part might actually be impossible because of an ambiguous evaluation order for a case like in timezones package

var x: int64
x = read(int32) # call params say int32 but return type wants int64

@SirOlaf SirOlaf changed the title Experiment: typeRel for inferGenericTypes Let inferGenericTypes continue if a param is already bound Aug 5, 2023
@SirOlaf SirOlaf marked this pull request as ready for review August 5, 2023 19:57
@Araq Araq merged commit 67122a9 into nim-lang:devel Aug 6, 2023
16 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2023

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

Hint: mm: orc; opt: speed; options: -d:release
168497 lines; 8.269s; 611.668MiB peakmem

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