Skip to content

Commit 3638837

Browse files
committed
Merge commit '2907aa04170e233faeb995aa99bd20eb77cd91d1'
Conflicts: mcs/mcs/anonymous.cs
2 parents d3c5fb0 + 2907aa0 commit 3638837

File tree

8 files changed

+124
-22
lines changed

8 files changed

+124
-22
lines changed

mcs/errors/cs0136-18.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// CS0136: A local variable named `arg' cannot be declared in this scope because it would give a different meaning to `arg', which is already used in a `parent or current' scope to denote something else
2+
// Line: 11
3+
4+
using System;
5+
6+
class A (Func<int, int> barg)
7+
{
8+
}
9+
10+
class B (int arg)
11+
: A ((arg) => 1)
12+
{
13+
}

mcs/errors/cs0136-19.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// CS0136: A local variable named `arg' cannot be declared in this scope because it would give a different meaning to `arg', which is already used in a `parent or current' scope to denote something else
2+
// Line: 11
3+
4+
using System;
5+
6+
partial class PC
7+
{
8+
Func<int, int> f = (arg) => 1;
9+
}
10+
11+
partial class PC (int arg)
12+
{
13+
}

mcs/mcs/anonymous.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,18 +1329,30 @@ protected virtual ParametersCompiled ResolveParameters (ResolveContext ec, TypeI
13291329
return Parameters;
13301330
}
13311331

1332-
protected override Expression DoResolve (ResolveContext ec)
1332+
protected override Expression DoResolve (ResolveContext rc)
13331333
{
1334-
var isPlayScript = ec.FileType == SourceFileType.PlayScript;
1334+
var isPlayScript = rc.FileType == SourceFileType.PlayScript;
13351335

1336-
if (ec.HasSet (ResolveContext.Options.ConstantScope)) {
1337-
ec.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
1336+
if (rc.HasSet (ResolveContext.Options.ConstantScope)) {
1337+
rc.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
13381338
return null;
13391339
}
13401340

13411341
//
1342-
// Set class type, set type
1342+
// Update top-level block generated duting parsing with actual top-level block
13431343
//
1344+
if (rc.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer) && rc.CurrentMemberDefinition.Parent.PartialContainer.PrimaryConstructorParameters != null) {
1345+
var tb = rc.ConstructorBlock.ParametersBlock.TopBlock;
1346+
if (Block.TopBlock != tb) {
1347+
Block b = Block;
1348+
while (b.Parent != Block.TopBlock && b != Block.TopBlock)
1349+
b = b.Parent;
1350+
1351+
b.Parent = tb;
1352+
tb.IncludeBlock (Block, Block.TopBlock);
1353+
b.ParametersBlock.TopBlock = tb;
1354+
}
1355+
}
13441356

13451357
eclass = ExprClass.Value;
13461358

@@ -1351,25 +1363,14 @@ protected override Expression DoResolve (ResolveContext ec)
13511363
//
13521364
type = InternalType.AnonymousMethod;
13531365

1354-
if (!DoResolveParameters (ec))
1366+
if (!DoResolveParameters (rc))
13551367
return null;
13561368

1357-
//<<<<<<< HEAD
1358-
//#if !STATIC
1359-
// // FIXME: The emitted code isn't very careful about reachability
1360-
// // so, ensure we have a 'ret' at the end
1361-
// BlockContext bc = ec as BlockContext;
1362-
// if (bc != null && bc.CurrentBranching != null && bc.CurrentBranching.CurrentUsageVector.IsUnreachable)
1363-
// bc.NeedReturnLabel ();
1364-
//#endif
1365-
//
13661369
// Cast to Delgate for PlayScript (forces implicit conversion to Func<> or Action<> delegate types).
13671370
if (isPlayScript) {
1368-
return new Cast(new TypeExpression(ec.BuiltinTypes.Delegate, this.Location), this, this.Location).Resolve (ec);
1371+
return new Cast(new TypeExpression(rc.BuiltinTypes.Delegate, this.Location), this, this.Location).Resolve (rc);
13691372
}
13701373

1371-
//=======
1372-
//>>>>>>> d12330eda7746321b4611865d11e932e53ac55b8
13731374
return this;
13741375
}
13751376

mcs/mcs/class.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,8 +1823,12 @@ bool DoDefineBaseType ()
18231823
// defined after current container
18241824
//
18251825
if (class_partial_parts != null) {
1826-
foreach (var pp in class_partial_parts)
1826+
foreach (var pp in class_partial_parts) {
1827+
if (pp.PrimaryConstructorBaseArguments != null)
1828+
PrimaryConstructorBaseArguments = pp.PrimaryConstructorBaseArguments;
1829+
18271830
pp.DoDefineBaseType ();
1831+
}
18281832

18291833
}
18301834

@@ -2915,7 +2919,7 @@ protected virtual Constructor DefineDefaultConstructor (bool is_static)
29152919

29162920
AddConstructor (c, true);
29172921
if (PrimaryConstructorBlock == null) {
2918-
c.Block = new ToplevelBlock (Compiler, c.ParameterInfo, Location) {
2922+
c.Block = new ToplevelBlock (Compiler, parameters, Location) {
29192923
IsCompilerGenerated = true
29202924
};
29212925
} else {

mcs/mcs/expression.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12372,8 +12372,10 @@ public override void EmitStatement (EmitContext ec)
1237212372

1237312373
public override void FlowAnalysis (FlowAnalysisContext fc)
1237412374
{
12375-
foreach (var initializer in initializers)
12376-
initializer.FlowAnalysis (fc);
12375+
foreach (var initializer in initializers) {
12376+
if (initializer != null)
12377+
initializer.FlowAnalysis (fc);
12378+
}
1237712379
}
1237812380
}
1237912381

mcs/mcs/statement.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,9 @@ public ToplevelBlock TopBlock {
40214021
get {
40224022
return top_block;
40234023
}
4024+
set {
4025+
top_block = value;
4026+
}
40244027
}
40254028

40264029
public bool Resolved {
@@ -4799,6 +4802,24 @@ public bool GetLocalName (string name, Block block, ref INamedBlockVariable vari
47994802
return false;
48004803
}
48014804

4805+
public void IncludeBlock (ParametersBlock pb, ToplevelBlock block)
4806+
{
4807+
if (block.names != null) {
4808+
foreach (var n in block.names) {
4809+
var variable = n.Value as INamedBlockVariable;
4810+
if (variable != null) {
4811+
if (variable.Block.ParametersBlock == pb)
4812+
AddLocalName (n.Key, variable, false);
4813+
continue;
4814+
}
4815+
4816+
foreach (var v in (List<INamedBlockVariable>) n.Value)
4817+
if (v.Block.ParametersBlock == pb)
4818+
AddLocalName (n.Key, v, false);
4819+
}
4820+
}
4821+
}
4822+
48024823
// <summary>
48034824
// This is used by non-static `struct' constructors which do not have an
48044825
// initializer - in this case, the constructor must initialize all of the
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
class X
5+
{
6+
internal static Dictionary<Type, Func<string, string>> Test = new Dictionary<Type, Func<string, string>> { {
7+
typeof (int),
8+
metadata => "1"
9+
}, {
10+
typeof (uint),
11+
metadata => "2"
12+
},
13+
};
14+
15+
public static void Main ()
16+
{
17+
}
18+
}

mcs/tests/test-primary-ctor-09.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
class A (Func<int, int> barg)
4+
{
5+
public Func<int, int> BaseArg = barg;
6+
}
7+
8+
partial class PC
9+
{
10+
public Func<int, int> f1 = (a) => arg;
11+
}
12+
13+
partial class PC (int arg)
14+
: A ((a) => arg)
15+
{
16+
}
17+
18+
class X
19+
{
20+
public static int Main ()
21+
{
22+
if (new PC (3).f1 (4) != 3)
23+
return 1;
24+
25+
if (new PC (3).BaseArg (4) != 3)
26+
return 2;
27+
28+
return 0;
29+
}
30+
}

0 commit comments

Comments
 (0)