Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 4, 2025

The BC30059 error documentation was missing guidance for developers encountering this error when trying to initialize arrays as default values for optional parameters. This is a common scenario that wasn't adequately covered in the existing documentation.

Changes Made

Enhanced docs/visual-basic/misc/bc30059.md with:

  • Updated error description to include array initialization in optional parameters as a specific cause
  • New comprehensive section "Array initialization in optional parameters" explaining why this fails
  • Three practical alternative solutions:
    1. Using ParamArray instead of optional parameters
    2. Setting default to Nothing and initializing in the method body
    3. Providing method overloads without the parameter
  • Working code examples for each solution showing proper Visual Basic syntax
  • Enhanced "See also" section with links to related documentation on optional parameters, parameter arrays, and array initialization

Problem Addressed

The original issue showed code like this failing with BC30059:

Public Function MyFun(Optional filters() As (String, String) = New (String, String)() {}) As Boolean

The documentation now clearly explains why this fails (array initialization is not a constant expression) and provides multiple working alternatives that achieve the same goal.

Validation

  • All referenced documentation links exist and are correct
  • Markdown linting passes with zero errors
  • Code examples use proper Visual Basic syntax
  • Solutions directly address the reported use case

Fixes #20882.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/visual-basic/misc/bc30059.md docs/visual-basic/misc/bc30059

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Sep 4, 2025
@Copilot Copilot AI changed the title [WIP] Doesn't cover initialization of an empty array Enhance BC30059 documentation with array initialization guidance for optional parameters Sep 4, 2025
@Copilot Copilot AI requested a review from BillWagner September 4, 2025 19:41
Copilot finished work on behalf of BillWagner September 4, 2025 19:41
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review September 5, 2025 14:05
@BillWagner BillWagner requested a review from a team as a code owner September 5, 2025 14:05
@BillWagner BillWagner requested a review from gewarren September 5, 2025 14:05
@@ -20,9 +20,90 @@ A `Const` statement doesn't properly initialize a constant, or an array declarat
1. If the declaration is a `Const` statement, check to make sure the constant is initialized with a literal, a previously declared constant, an enumeration member, or a combination of literals, constants, and enumeration members combined with operators.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be bullets instead of numbered list according to style rules.

@@ -20,9 +20,90 @@ A `Const` statement doesn't properly initialize a constant, or an array declarat
1. If the declaration is a `Const` statement, check to make sure the constant is initialized with a literal, a previously declared constant, an enumeration member, or a combination of literals, constants, and enumeration members combined with operators.

2. If the declaration specifies an array, check to see if a variable is being used to specify the number of elements. If so, replace the variable with a constant expression.

3. If you're trying to initialize an array as the default value for an optional parameter, use one of the alternative approaches described in the [Array initialization in optional parameters](#array-initialization-in-optional-parameters) section below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. If you're trying to initialize an array as the default value for an optional parameter, use one of the alternative approaches described in the [Array initialization in optional parameters](#array-initialization-in-optional-parameters) section below.
3. If you're trying to initialize an array as the default value for an optional parameter, use one of the alternative approaches described in the [Array initialization in optional parameters](#array-initialization-in-optional-parameters) section.

Comment on lines +39 to +41
### Alternative solutions

#### Option 1: Use ParamArray instead of Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Alternative solutions
#### Option 1: Use ParamArray instead of Optional
### Solution 1: Use ParamArray instead of Optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no text between the H3 and H4s, seems like it's better to skip the "Alternative solutions" heading altogether.

MyFun(("name1", "value1"), ("name2", "value2"))
```

#### Option 2: Use Nothing as default and initialize in the method body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Option 2: Use Nothing as default and initialize in the method body
### Solution 2: Use Nothing as default and initialize in the method body

MyFun({("name", "value")})
```

#### Option 3: Provide an overload without the parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Option 3: Provide an overload without the parameter
### Solution 3: Provide an overload without the parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-visualbasic/svc errors-warnings/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doesn't cover initialization of an empty array
3 participants