Closed AdamSpeight2008 closed 7 years ago
I really like this feature. @AnthonyDGreen what do you think? @AdamSpeight2008 There are a few further areas of research to investigate...
@ljw1004
The current emit
and metadata
unit test pass.
The major block is #12690, which is affects the ExpressionEvaluator
unit tests.
Overload resolution issue I think I fixed in [#12629](. commit: link
Analyser and CodeFix need a way of validating the presence of the Feature flag. (currently not of github)
Or I could do a sample parse and check for the error, BC30812 Optional parameters must specify a default value
. I think that is kind of hacky
@ljw1004 @AnthonyDGreen
Reran the unit test after merging in Roslyn PR. They pass (No Failures) locally, waiting on the results of the Roslyn PR Build. When they pass I'll do a tidy up of the code to reduce the size of the pull request. Refactor some of the method names.
Implicit Default Value On Optional Parameter
The aim of the proposal is to see if it possible to make the default value, that currently as to explicitly expressed can be made optional.
Examples
The existing code
can written as
This would reduce a lot of boiler-plate code for the likely common usage of just needing the default value of the type (eg
parameter = default(T)
). Will still permitting the expressing of a different value, should the coder require one.Research
Grammar Definition
So the Visual Basic Grammer (VB14) allows for an optional default value
( Equals ConstantExpression )?
.Errors
Default Value For Non Optional Parameter
Obsolete Optional Without Value
==Compat== Must maintain this when language version doesn't support Implicit Default Value On Optional Parameter.
Caller Information Attributes
(Compat) These should continue work, even when using the feature.
Code Examination
Parser
After a search of the Parser code
Make the body of the second condition dependant on the feature's availability.
Depending on the code change, the following could be null
value = nothing
andequals = nothing
. We would require to modify these conditions.ParseParameters
I do not see any potential issue within this function, when using the feature.
I do not see any potential issue within this function, when using the feature.
Syntax
SyntaxFactory.Parameter
Semantics
Overload Resolution
OverloadResolution.OptionalArgument (Potential Issue)
DefaultValue = Nothing
?Is it expected to be non-null?
Handle Optional Parameters (Potential Issue)
null
then should I do check for the feature and assign "default" value todefault argument
?Symbol
ParameterSymbol (Potential Issue)
This feature would not have an explicit default value, as it let's the coder not declare one. So the options are:-
At the usage sites, catch the exception then, modify the usage.
Emit.ParameterSymbolAdapter (Potential Issue)
HasMetadateConstantValue
GetMetadataConstantValue
IParameterDefinition_HasDefaultValue
Emit.NoPia.EmbeddedParameter (Potential Issue)
HasDefaultValue
GetDefaultValue
Binding
Binding.Binder_Invocation (Potential Issue)
HasDefaultValue
indicates(Parameter.IsOptional == True) && (Parameter.DefaultValue <> null)
<CallerLineNumber>
,<CallerMethodName>
,<CallerFilename>
ElseIf param.IsOptional Then
Here( Optional p As Integer )