-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Enable consumption of init-only properties in VB. #50414
Conversation
@jcouv, @dotnet/roslyn-compiler Please review. |
@jcouv, @dotnet/roslyn-compiler Please review. |
Do we have to do anything for displaying init-only accessor or property ( Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:12 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
I didn't understand how this works. There is no compilation error, and yet the init-only setter doesn't seem to be invoked. Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:752 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
Is there any risk that the ByRef property could leak and be exercised past the construction/initialization phase? #Closed Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:337 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
nit: It would be simpler to follow this test if the setter simply threw if Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:740 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
@@ -2027,7 +2031,7 @@ End Module").Path | |||
' - update project-system to recognize the new value and pass it through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line about IDE drop-down can be removed (the drop-down was removed for C#, so won't be added for VB) and I think we didn't need to modify project-system repo anymore (I don't see a PR there for 15.3 or 15.6). #Closed
@@ -2027,7 +2031,7 @@ End Module").Path | |||
' - update project-system to recognize the new value and pass it through | |||
' - update all the tests that call this canary | |||
' - update the command-line documentation (CommandLine.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
' - update the command-line documentation (CommandLine.md) [](start = 12, length = 58)
Let's update the doc.
I think vbc -langversion:?
will automatically pick up the new version, but may be worth a try. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update the doc.
I am not sure what is there to update. It doesn't look like the doc lists specific versions or I am looking at a wrong document.
I think vbc -langversion:? will automatically pick up the new version, but may be worth a try.
It does.
Supported language versions:
default
9
10
11
12
14
15
15.3
15.5
16 (default)
16.9 (latest)
latest
In reply to: 556982209 [](ancestors = 556982209)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it looks like the bullet for CommandLine.md is obsolete too. We'll remove it next time. Thanks
In reply to: 558429780 [](ancestors = 558429780,556982209)
@@ -2068,8 +2073,9 @@ End Module").Path | |||
Assert.Equal(LanguageVersion.VisualBasic15_3, LanguageVersion.VisualBasic15_3.MapSpecifiedToEffectiveVersion()) | |||
Assert.Equal(LanguageVersion.VisualBasic15_5, LanguageVersion.VisualBasic15_5.MapSpecifiedToEffectiveVersion()) | |||
Assert.Equal(LanguageVersion.VisualBasic16, LanguageVersion.VisualBasic16.MapSpecifiedToEffectiveVersion()) | |||
Assert.Equal(LanguageVersion.VisualBasic16_9, LanguageVersion.VisualBasic16_9.MapSpecifiedToEffectiveVersion()) | |||
Assert.Equal(LanguageVersion.VisualBasic16, LanguageVersion.Default.MapSpecifiedToEffectiveVersion()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LanguageVersion.Default [](start = 56, length = 23)
Let's confirm what version Default
should map to. I think we could have it point to 16.9 now. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to moving to VB16 we had mapping work this way:
Select Case version
Case LanguageVersion.Latest
Return LanguageVersion.VisualBasic15_5
Case LanguageVersion.Default
Return LanguageVersion.VisualBasic15
Case Else
Return version
End Select
I am following the same pattern.
In reply to: 556982329 [](ancestors = 556982329)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
Return False | ||
|
||
Case BoundKind.MeReference, BoundKind.MyBaseReference, BoundKind.MyClassReference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C# we're also going to allow certain conversions on this
.
See #50424 #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C# we're also going to allow certain conversions on this.
I would prefer to deal with this recent design change (BTW, has the spec been updated?) separately. Please don't close #50053 once you are done with C#, instead add a comment that VB should also be adjusted and assign the issue to me.
In reply to: 556982365 [](ancestors = 556982365)
Return False | ||
End If | ||
|
||
' ok: New C() With { .InitOnlyProperty = ... } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C# we had to handle nested initializers differently. Does VB also support nested initializers? (same question for With
expression) #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C# we had to handle nested initializers differently. Does VB also support nested initializers? (same question for With expression)
There is no such thing as a nested initializer in VB. Nested with statements are allowed but only the immediate one is in effect at any given point. In other words, there is no fallback to the outer With statement, the receiver is overwritten.
In reply to: 556982409 [](ancestors = 556982409)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with review pass (iteration 1)
I don't think so. There is no such thing as init-only properties in VB. No special syntax for them, etc. This is just another case of metadata that are outside of the language specification that we are simply doing our best to consume. In reply to: 759860550 [](ancestors = 759860550) Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:12 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
This is how ByRef works in VB. If it cannot write, it doesn't write and only reads. This is how regular RValues, readonly fields, and readonly properties (including auto-properties) are handled. No errors reported. In reply to: 759860715 [](ancestors = 759860715) Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:752 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
Perhaps I am misinterpreting the question. This function doesn't get direct "access" to the property. Compiler passes a reference to a local and writes back to the property after the call when writing back is expected. In reply to: 759860771 [](ancestors = 759860771) Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:337 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
This is VB "dynamic". Latebinder is inside VB runtime library and I don't think we are going to update it. In reply to: 759860911 [](ancestors = 759860911) Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:3055 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
@dotnet/roslyn-compiler Please review. |
Looking. #Resolved |
@@ -933,7 +933,7 @@ internal bool CalculateUseSiteDiagnostic(ref DiagnosticInfo result) | |||
|
|||
// Check return type, custom modifiers, parameters | |||
if (DeriveUseSiteDiagnosticFromType(ref result, this.ReturnTypeWithAnnotations, | |||
MethodKind == MethodKind.PropertySet ? | |||
IsInitOnly ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in the future, it would be great to have this bug fix as either a separate commit or a separate PR, as it doesn't really seem related to VB consuming such properties. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: in the future, it would be great to have this bug fix as either a separate commit or a separate PR, as it doesn't really seem related to VB consuming such properties.
I think the change is related to the feature I am working on. And I don't think it makes sense to separate this change and have compilers behave inconsistently.
In reply to: 557614115 [](ancestors = 557614115)
<value>'{0}' cannot override init-only '{1}'.</value> | ||
</data> | ||
<data name="ERR_PropertyDoesntImplementInitOnly" xml:space="preserve"> | ||
<value>Init-only '{0}' cannot be implemented.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Init-only [](start = 11, length = 9)
Perhaps Init-only property
? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps Init-only property?
Symbol display does that. Similar exiting diagnostics doesn't duplicate member kind in suggested way.
In reply to: 557615621 [](ancestors = 557615621)
propertyAccess = propertyAccess.Update(propertyAccess.PropertySymbol, propertyAccess.PropertyGroupOpt, propertyAccess.AccessKind, isWriteable:=True, | ||
propertyAccess.IsLValue, propertyAccess.ReceiverOpt, propertyAccess.Arguments, propertyAccess.DefaultArguments, | ||
propertyAccess.Type) | ||
target = propertyAccess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check LangVersion here? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't, a comment as to why would be appreciated.
In reply to: 557618151 [](ancestors = 557618151)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't, a comment as to why would be appreciated.
We are simply deciding if the property is writable or not, the property is writable or not writable regardless of a language version. I don't think any comments about why we don't do something here are necessary, we are not doing a lot of things here.
In reply to: 557618498 [](ancestors = 557618498,557618151)
It would be good to call out what is special about this IL that can't be written in C# so I don't have reverse-engineer the test when looking at it. Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:1995 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 1), with Julien's suggestions addressed.
Cool, so this remains safe (it's not bypassing init rule). Thanks In reply to: 760252469 [](ancestors = 760252469,759860715) Refers to: src/Compilers/VisualBasic/Test/Semantic/Semantics/InitOnlyMemberTests.vb:752 in 8d75b3e. [](commit_id = 8d75b3e, deletion_comment = False) |
@jcouv Addressed feedback. |
Not for this PR: We'll probably want some documentation for team feature review next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 3)
Closes #44870.
Closes #49469.