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

cgen or internal error when passing @[] to seq[string] or T (ditto with {} and set[uint8]) #15721

Open
timotheecour opened this issue Oct 25, 2020 · 2 comments · May be fixed by #24250
Open

Comments

@timotheecour
Copy link
Member

timotheecour commented Oct 25, 2020

passing @[] to seq[string] or OtherType gives a cgen error.

I use the following pattern as a very convenient way to have a compile time Option[T] type, however it doesn't work with T = seq[string] when passing @[]

Example 1

when true: # gitissue D20201026T002034:here
  proc fn(a = 4, b: seq[string] or tuple[] = ()) =
    discard # eg: when b is tuple[]: ...
  fn(1)
  fn(1, @[""])
  var a: seq[string] = @[]
  fn(1, a)
  fn(1, seq[string](@[]))
  fn(1, @[]) # BUG: error: conflicting types for 'fn__d58I39cH9a6bcpi3QDPJ5dBA'

Current Output

@mt11189.nim.c:354:31: error: conflicting types for 'fn__d58I39cH9a6bcpi3QDPJ5dBA'

Expected Output

works

Example 2

likewise with {} for set:

when true: # gitissue D20201026T002034
  proc fn(a = 4, b: set[uint8] or tuple[] = ()) =
    discard # eg: when b is tuple[]: ...
  fn(1)
  fn(1, {1'u8})
  var a: set[uint8] = {}
  fn(1, a)
  fn(1, set[uint8]({}))
  fn(1, {}) # BUG: internal error: invalid kind for lastOrd(tyEmpty)

Additional Information

devel 1.5.1 2265955
see also #15722

@timotheecour timotheecour changed the title cgen error when passing @[] to seq[string] or OtherType, cgen error when passing @[] to seq[string] or OtherType Oct 25, 2020
@timotheecour timotheecour changed the title cgen error when passing @[] to seq[string] or OtherType cgen or internal error when passing @[] to seq[string] or T (ditto with {} and set[uint8]) Oct 25, 2020
@disruptek
Copy link
Contributor

The codegen is using TGenericSeq for the prototype and seqEmpty for the definition. Feels like something I should fix. 😁

@metagn
Copy link
Collaborator

metagn commented Sep 16, 2023

seq[empty] matches seq[string] or T because it matches seq[string], but compiler cannot figure out how to convert seq[empty] to seq[string] or T so it stays as seq[empty], causes codegen error (confirm with echo typeof(b)). Kind of like #1214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants