Is this a bug in the preprocessor?

0 votes
asked Jan 22 in Bug by chris (2,540 points)

Seems to be an issue using a variable to define the color of a rectangle with a stereotype, when the name and stereotype are specified using a procedure?

@startuml
!$background_color = "#808080"
!procedure $call_proc($a, $b)
$a <<$b>>
!endprocedure
rectangle name <<stereotypename>> #808080 [
Thisisfine
]
rectangle $call_proc("asddd", "ewrwerwer") #808080 [
AlsoFine
]
rectangle $call_proc("asddd", "ewrwerwer") $background_color [
NotFine
]
@enduml

Example

1 Answer

+1 vote
answered Jan 23 by The-Lu (62,540 points)

Hello C., and all,

Here is a workaround, using function, as:

@startuml
!$background_color = "#808080"
!function $call_proc($a, $b)
  !return %string($a + "<<" + $b +">>")
!endfunction

rectangle name0 $background_color [
Thisisfine
]
rectangle name <<stereotypename>> #808080 [
Thisisfine
]
rectangle $call_proc("asddd", "ewrwerwer") #808080 [
AlsoFine
]
rectangle $call_proc("asddd", "ewrwerwer") $background_color [
NotFine
]
@enduml

If that can help,
Regards,
Th.

commented Jan 23 by chris (2,540 points)
edited Jan 25 by chris
Thanks The-Lu! For anyone checking T's answer and noticing the 'NotFine' rectangle doesn't show - that was my lazy example, just change the Name to asddd2 or something :)

This is still a bug though, right? The procedure should work, rather than injecting a string
commented Jan 25 by kirchsth (4,780 points)

Yes there could be a bug in the preprocessor:

I executed following puml with
`java -jar plantuml.jar -preproc C:\temp\procedure.puml`

@startuml
!$background_color = "#808080"

!procedure $call_proc($a, $b)
$a <<$b>>
!endprocedure

rectangle name <<stereotypename>> #808080 [
$background_color 1
]

rectangle $call_proc("asddd", "ewrwerwer") #808080 [
$background_color 3
]

rectangle $call_proc("asddd", "ewrwerwer") $background_color [
$background_color 4
]
@enduml

and get a *.preproc with (only) one unreplaced $background_color 

@startuml
rectangle name <<stereotypename>> #808080 [
#808080 1
]
rectangle asddd <<ewrwerwer>> #808080 [
#808080 3
]
rectangle asddd <<ewrwerwer>>
$background_color [
#808080 4
]
@enduml

therefore I think it could be a problem in preprocessor (independent of of the procedure/function logic).

BR Helmut

...