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

Documentation with when branch is missing field types #9899

Closed
mratsim opened this issue Dec 8, 2018 · 2 comments · Fixed by #22077
Closed

Documentation with when branch is missing field types #9899

mratsim opened this issue Dec 8, 2018 · 2 comments · Fixed by #22077
Labels
Documentation Content Related to documentation content (not generation). Documentation Generation Related to documentation generation (but not content). Easy Hacktoberfest (Open) Issues suitable for Hacktoberfest, open for working on.

Comments

@mratsim
Copy link
Collaborator

mratsim commented Dec 8, 2018

Test case: The current options module documentation is missing type for fields:

https://nim-lang.org/docs/options.html#7

Option[T] = object
  when T is SomePointer:
    val
  else:
      val
      has

While this is what is declared:

Nim/lib/pure/options.nim

Lines 75 to 82 in 72e15ff

type
Option*[T] = object
## An optional type that stores its value and state separately in a boolean.
when T is SomePointer:
val: T
else:
val: T
has: bool

@mratsim mratsim added Documentation Content Related to documentation content (not generation). Documentation Generation Related to documentation generation (but not content). labels Dec 8, 2018
@nc-x
Copy link
Contributor

nc-x commented May 4, 2019

This is a general issue not related to docgen:

proc x(n: int): string = discard

x:
  type
    Option*[T] = object
      ## An optional type that stores its value and state separately in a boolean.
      when T is void:
        val: T
      else:
        val: T
        has: bool

nim c t.nim gives -

t.nim(3, 1) Error: type mismatch: got <void>
but expected one of:
proc x(n: int): string

expression: x:
  type
    Option[T] = object
      when T is void:            ## An optional type that stores its value and state separately in a boolean.
        val
      else:
          val
          has

This is because semRecordNodeAux for nkRecWhen for generics evaluates stuff early.

A simple fix is to remove this line

it.sons[idx] = if newf.len == 1: newf[0] else: newf

but then obviously it creates other issues.


Another fix would be to check for this case here -

Nim/compiler/docgen.nim

Lines 354 to 356 in 9c3e23e

else:
dispA(d.conf, result, "<span class=\"Identifier\">$1</span>",
"\\spanIdentifier{$1}", [rope(esc(d.target, literal))])

and use PSym_variable.typ to get what we want. (And similarly for renderer or whatever the compiler uses to print in errors).

There may be other ways to fix it, IDK.

cc @Araq

@metagn
Copy link
Collaborator

metagn commented Jun 11, 2023

Fixed by #21017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Content Related to documentation content (not generation). Documentation Generation Related to documentation generation (but not content). Easy Hacktoberfest (Open) Issues suitable for Hacktoberfest, open for working on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants