|
|
|
@ -323,14 +323,7 @@ namespace Mono.CSharp {
@@ -323,14 +323,7 @@ namespace Mono.CSharp {
|
|
|
|
|
public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs) |
|
|
|
|
{ |
|
|
|
|
if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) { |
|
|
|
|
rc.Report.SymbolRelatedToPreviousError (type); |
|
|
|
|
if (rc.CurrentInitializerVariable != null) { |
|
|
|
|
rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer", |
|
|
|
|
type.GetSignatureForError (), GetSignatureForError ()); |
|
|
|
|
} else { |
|
|
|
|
rc.Report.Error (1612, loc, "Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable", |
|
|
|
|
GetSignatureForError ()); |
|
|
|
|
} |
|
|
|
|
// Already reported as CS1612
|
|
|
|
|
} else { |
|
|
|
|
rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer"); |
|
|
|
|
} |
|
|
|
@ -2947,6 +2940,30 @@ namespace Mono.CSharp {
@@ -2947,6 +2940,30 @@ namespace Mono.CSharp {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public bool ResolveInstanceExpression (ResolveContext rc, Expression rhs) |
|
|
|
|
{ |
|
|
|
|
if (!ResolveInstanceExpressionCore (rc, rhs)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Check intermediate value modification which won't have any effect
|
|
|
|
|
//
|
|
|
|
|
if (rhs != null && InstanceExpression.Type.IsStruct && |
|
|
|
|
(InstanceExpression is PropertyExpr || InstanceExpression is IndexerExpr || InstanceExpression is Invocation)) { |
|
|
|
|
|
|
|
|
|
if (rc.CurrentInitializerVariable != null) { |
|
|
|
|
rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer", |
|
|
|
|
InstanceExpression.Type.GetSignatureForError (), InstanceExpression.GetSignatureForError ()); |
|
|
|
|
} else { |
|
|
|
|
rc.Report.Error (1612, loc, |
|
|
|
|
"Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable", |
|
|
|
|
InstanceExpression.GetSignatureForError ()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool ResolveInstanceExpressionCore (ResolveContext rc, Expression rhs) |
|
|
|
|
{ |
|
|
|
|
if (IsStatic) { |
|
|
|
|
if (InstanceExpression != null) { |
|
|
|
@ -3010,7 +3027,7 @@ namespace Mono.CSharp {
@@ -3010,7 +3027,7 @@ namespace Mono.CSharp {
|
|
|
|
|
|
|
|
|
|
var me = InstanceExpression as MemberExpr; |
|
|
|
|
if (me != null) { |
|
|
|
|
me.ResolveInstanceExpression (rc, rhs); |
|
|
|
|
me.ResolveInstanceExpressionCore (rc, rhs); |
|
|
|
|
|
|
|
|
|
// Using this check to detect probing instance expression resolve
|
|
|
|
|
if (!rc.OmitStructFlowAnalysis) { |
|
|
|
@ -4020,19 +4037,20 @@ namespace Mono.CSharp {
@@ -4020,19 +4037,20 @@ namespace Mono.CSharp {
|
|
|
|
|
//
|
|
|
|
|
// Foo (int i) is better than Foo (int i, long l = 0)
|
|
|
|
|
// Foo (params int[] args) is better than Foo (int i = 0, params int[] args)
|
|
|
|
|
// Foo (string s, params string[] args) is better than Foo (params string[] args)
|
|
|
|
|
//
|
|
|
|
|
// Prefer non-optional version
|
|
|
|
|
//
|
|
|
|
|
// LAMESPEC: Specification claims this should be done at last but the opposite is true
|
|
|
|
|
//
|
|
|
|
|
if (candidate_params == best_params && candidate_pd.Count != best_pd.Count) { |
|
|
|
|
if (candidate_pd.Count >= best_pd.Count) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
if (j < candidate_pd.Count && candidate_pd.FixedParameters[j].HasDefaultValue) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
if (j < best_pd.Count && best_pd.FixedParameters[j].HasDefaultValue) |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
return candidate_pd.Count >= best_pd.Count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -4374,16 +4392,32 @@ namespace Mono.CSharp {
@@ -4374,16 +4392,32 @@ namespace Mono.CSharp {
|
|
|
|
|
// if the type matches
|
|
|
|
|
//
|
|
|
|
|
Expression e = fp.DefaultValue; |
|
|
|
|
if (!(e is Constant) || e.Type.IsGenericOrParentIsGeneric || e.Type.IsGenericParameter) { |
|
|
|
|
if (!(e is Constant) || e.Type != ptypes [i]) { |
|
|
|
|
//
|
|
|
|
|
// LAMESPEC: No idea what the exact rules are for System.Reflection.Missing.Value instead of null
|
|
|
|
|
//
|
|
|
|
|
if (e == EmptyExpression.MissingValue && ptypes[i].BuiltinType == BuiltinTypeSpec.Type.Object || ptypes[i].BuiltinType == BuiltinTypeSpec.Type.Dynamic) { |
|
|
|
|
var ptype = ptypes [i]; |
|
|
|
|
if (e == EmptyExpression.MissingValue && ptype.BuiltinType == BuiltinTypeSpec.Type.Object || ptype.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { |
|
|
|
|
e = new MemberAccess (new MemberAccess (new MemberAccess ( |
|
|
|
|
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Reflection", loc), "Missing", loc), "Value", loc); |
|
|
|
|
} else if (e is Constant) { |
|
|
|
|
//
|
|
|
|
|
// Handles int to int? conversions
|
|
|
|
|
//
|
|
|
|
|
e = Convert.ImplicitConversionStandard (ec, e, ptype, loc); |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// When constant type paramter contains type argument
|
|
|
|
|
//
|
|
|
|
|
// Foo (T[] arg = null)
|
|
|
|
|
//
|
|
|
|
|
if (e == null) { |
|
|
|
|
e = new DefaultValueExpression (new TypeExpression (ptype, loc), loc); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
e = new DefaultValueExpression (new TypeExpression (ptypes [i], loc), loc); |
|
|
|
|
e = new DefaultValueExpression (new TypeExpression (ptype, loc), loc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e = e.Resolve (ec); |
|
|
|
|
} |
|
|
|
@ -4852,13 +4886,18 @@ namespace Mono.CSharp {
@@ -4852,13 +4886,18 @@ namespace Mono.CSharp {
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Check ObsoleteAttribute on the best method
|
|
|
|
|
// Don't run possibly expensive checks in probing mode
|
|
|
|
|
//
|
|
|
|
|
ObsoleteAttribute oa = best_candidate.GetAttributeObsolete (); |
|
|
|
|
if (oa != null && !rc.IsObsolete) |
|
|
|
|
AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report); |
|
|
|
|
if (!rc.IsInProbingMode) { |
|
|
|
|
//
|
|
|
|
|
// Check ObsoleteAttribute on the best method
|
|
|
|
|
//
|
|
|
|
|
ObsoleteAttribute oa = best_candidate.GetAttributeObsolete (); |
|
|
|
|
if (oa != null && !rc.IsObsolete) |
|
|
|
|
AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report); |
|
|
|
|
|
|
|
|
|
best_candidate.MemberDefinition.SetIsUsed (); |
|
|
|
|
best_candidate.MemberDefinition.SetIsUsed (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
args = best_candidate_args; |
|
|
|
|
return (T) best_candidate; |
|
|
|
@ -4881,7 +4920,7 @@ namespace Mono.CSharp {
@@ -4881,7 +4920,7 @@ namespace Mono.CSharp {
|
|
|
|
|
if (a is CollectionElementInitializer.ElementInitializerArgument) { |
|
|
|
|
ec.Report.SymbolRelatedToPreviousError (method); |
|
|
|
|
if ((expected_par.FixedParameters[idx].ModFlags & Parameter.Modifier.RefOutMask) != 0) { |
|
|
|
|
ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have 'ref', or `out' modifier", |
|
|
|
|
ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have `ref' or `out' modifier", |
|
|
|
|
TypeManager.CSharpSignature (method)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -4915,7 +4954,12 @@ namespace Mono.CSharp {
@@ -4915,7 +4954,12 @@ namespace Mono.CSharp {
|
|
|
|
|
p2 = paramType.GetSignatureForErrorIncludingAssemblyName (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ec.Report.Error (1503, loc, |
|
|
|
|
if ((mod & Parameter.Modifier.RefOutMask) != 0) { |
|
|
|
|
p1 = Parameter.GetModifierSignature (a.Modifier) + " " + p1; |
|
|
|
|
p2 = Parameter.GetModifierSignature (a.Modifier) + " " + p2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ec.Report.Error (1503, a.Expr.Location, |
|
|
|
|
"Argument `#{0}' cannot convert `{1}' expression to type `{2}'", index, p1, p2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -6057,11 +6101,6 @@ namespace Mono.CSharp {
@@ -6057,11 +6101,6 @@ namespace Mono.CSharp {
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// if the property/indexer returns a value type, and we try to set a field in it
|
|
|
|
|
if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess) { |
|
|
|
|
Error_ValueAssignment (ec, right_side); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (eclass == ExprClass.Unresolved) { |
|
|
|
|
var expr = OverloadResolve (ec, right_side); |
|
|
|
|
if (expr == null) |
|
|
|
|