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

Cannot have Generic of Generics in Class diagram #3287

Closed
mohsenoid opened this issue Aug 4, 2022 · 6 comments · Fixed by #4534
Closed

Cannot have Generic of Generics in Class diagram #3287

mohsenoid opened this issue Aug 4, 2022 · 6 comments · Fixed by #4534
Assignees
Labels
Graph: Class Status: Approved Is ready to be worked on Type: Bug / Error Something isn't working or is incorrect

Comments

@mohsenoid
Copy link

mohsenoid commented Aug 4, 2022

Describe the bug
In the class diagram we can use ~ to achieve generic types, for instance:

classDiagram
  MyInterface: +StateFlow~Int~

But we cannot have Generic of generic <T>, for instnace:

classDiagram
  MyInterface: +StateFlow~List~Something~~

and the result is:

+StateFlow<List>Something<>

Related to #1120 and #1063

@mohsenoid mohsenoid added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Aug 4, 2022
@DeveloperPaul123
Copy link

Also related, these types of class diagrams with overloads of generic parameters do not render correctly either.

classDiagram

class A~T~ {
    +T value
}

class A~T,N~ {
    
}

class A~int~ {
    
}

A~int~ <|.. A~T~

Renders like:

classDiagram

class A~T~ {
    +T value
}

class A~T,N~ {
    
}

class A~int~ {
    
}

A~int~ <|.. A~T~
Loading

@sidharthv96
Copy link
Member

You can have List~Something~T~~ ids.

classDiagram
class A {
    List~Something~T~~ ids
}
Loading

So the issue is only with Class having generic types at the top. It might be a bug with the grammar.

@BlueDreaux
Copy link

BlueDreaux commented Mar 14, 2023

The nested generics is good but this doesn't yet seem to support lists of generics as commonly used for things like Map<K,V>.
Trying to diagram a class member that's a Map of string identifiers to a specific set of function types and the comma separated list of generics seems to give the current implementation a curve ball it didn't expect and it displays tilde's instead of the generics brackets.

Example:

class MyDemo<T> {
  private demoFns: Map<string, (s: T) => void>
}
classDiagram
  class MyDemo~T~ {
    #demoFns: Map~string, (s: T) => void~
  }
classDiagram
  class MyDemo~T~ {
    #demoFns: Map~string, (s: T) => void~
  }
Loading

@jgreywolf jgreywolf self-assigned this Mar 17, 2023
@jgreywolf jgreywolf added Status: Approved Is ready to be worked on Graph: Class and removed Status: Triage Needs to be verified, categorized, etc labels Mar 17, 2023
zomb-676 added a commit to zomb-676/CobaltDocs that referenced this issue Apr 5, 2023
@jgreywolf
Copy link
Contributor

Example:

class MyDemo<T> {
  private demoFns: Map<string, (s: T) => void>
}
classDiagram
  class MyDemo~T~ {
    #demoFns: Map~string, (s: T) => void~
  }

So you mean specifically when you use a => statement, since the parser trips on the bracket after the equals?

@BlueDreaux
Copy link

BlueDreaux commented Apr 18, 2023

Apologies, I was thinking it was for the lack of generic list support but in testing with a fresh look it seems to handle the list of generics just fine.

Test:

class MyDemo<X,Y> {
  private xVector: X
  private yVector: Y
}
classDiagram
  class MyDemo~X,Y~ {
    #xVector: X
    #yVector: Y
  }
Loading

Seems to also work with default type specifications:

class MyDemo<X=Vector,Y=Vector> {
  private xVector: X
  private yVector: Y
}
classDiagram
  class MyDemo~X=Vector,Y=Vector~ {
    #xVector: X
    #yVector: Y
  }
Loading

However, in coming up with an example that avoids the js shorthand (thanks for pointing that out) I'm still seeing tilde's instead of brackets in what's generated.

class MyDemo<X,Y> {
  tests: Map<string,(X,Y): void>
}
classDiagram
  class MyDemo~X,Y~ {
    tests: Map~string,(X,Y): void~
  }
Loading

If I simplify the class members to mappings with a simple generic list I get a Maximum call stack size exceeded error:

class MyDemo<X=any,Y=any> {
  xTests: Map<string,X>
  yTests: Map<string,Y>
}
classDiagram
  class MyDemo~X,Y~ {
    xTests: Map~string,X~
    yTests: Map~string,Y~
  }
Loading

Furthermore, if I try to express an anonymous object type mapping I get a Diagram error not found. error I'm not sure how to begin unraveling.

class MyDemo<X,Y> {
  tests: Map<string,{X,Y}>
}
classDiagram
  class MyDemo~X,Y~ {
    tests: Map~string,{X,Y}~
  }
Loading

@jgreywolf
Copy link
Contributor

The parser is choking on two aspects of this.

  1. The curly braces signal a "struct_start"/"struct_end" section, inside of which there should be the class definition with members.
  2. Commas inside of a generic value start/stop

This is going to take a little more time to find the best way to address this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Class Status: Approved Is ready to be worked on Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants