Good catch. This wasn't valid but has now been implemented for the next release: https://feedback.objo.dev/feature/682
The intended rule is that optional parameter defaults are runtime expressions. They are evaluated left-to-right, only when the caller omits that argument, and they may reference earlier parameters in the same parameter list.
So this is valid:
Function Describe(description As String, Optional count As Integer = description.Length) As String
Return description.Left(count)
End Function
Describe("runtime") # count = 7
Describe("runtime", 3) # count = 3; default is not evaluated
Defaults cannot reference themselves or later parameters, and the expression must type-check against the optional parameter’s declared type:
Function Bad(Optional count As Integer = other, Optional other As Integer = 1) As Integer
Return count
End Function
That now produces a compile-time error.