[svn] r7743: nemerle/trunk/ncc: generation/Typer3.n
testsuite/negative/bug-664.n
divan
svnadmin at nemerle.org
Fri Jul 6 22:59:01 CEST 2007
Log:
Deny properties in field initializers, because properties are "methods".
Author: divan
Date: Fri Jul 6 22:58:54 2007
New Revision: 7743
Modified:
nemerle/trunk/ncc/generation/Typer3.n
nemerle/trunk/ncc/testsuite/negative/bug-664.n
Modified: nemerle/trunk/ncc/generation/Typer3.n
==============================================================================
--- nemerle/trunk/ncc/generation/Typer3.n (original)
+++ nemerle/trunk/ncc/generation/Typer3.n Fri Jul 6 22:58:54 2007
@@ -1358,10 +1358,9 @@
| _ => ()
}
}
- mutable e = null;
when (is_ctor)
{
- e = match (current_local_fun.body) {
+ def e = match (current_local_fun.body) {
| FunBody.Typed (e) => e
| _ => Util.ice ("bad function body")
}
@@ -1389,19 +1388,53 @@
}
else
{
+ //first check base calls, add base() if needed
+ def e =
match (CtorCalls (e)) {
| (0, 0) =>
def bc = ptyper.TypeExpr ( <[ base () ]> );
def bc = ptyper2.Walk (Typer2.Context.TopLevel, bc);
- e = TExpr.Sequence (e.loc, e.ty, bc, e);
- | (1, 1) => ()
+ TExpr.Sequence (e.loc, e.ty, bc, e);
+ | (1, 1) => e
| (0, _) =>
Message.Warning ("Base constructor call can be missed");
+ e
| (x, _) when x > 1 =>
Message.Error ($"Base constructor call happens at least $x times");
+ e
| (_, y) =>
Message.Warning ($"Base constructor call can happen $y times");
+ e
}
+ def ini =
+ match (CurrentType.init_list) {
+ | [q]
+ => match (q) {
+ | PT.PExpr.Typed (e) => e
+ | _ => Util.ice ("bad field initializers");
+ }
+ | _ => null
+ };
+ when (clo_ini != null)
+ {
+ def f (_) {
+ | TExpr.Call (e, _, _) when IsCtor (e) => Some (true)
+ | _ => None ()
+ }
+ and ctor_calls (e) {
+ SimpleFlow (e, f, false, seq, fork)
+ }
+ and seq (_) {
+ | e :: _ => ctor_calls (e)
+ | _ => false
+ }
+ and fork (l) {
+ List.ForAll (l, seq)
+ }
+ when (!ctor_calls (e))
+ Message.Error ("closure utilizing 'this' reference is not allowed when base ctor call is not placed at the beginning of current ctor");
+ }
+ def e = InjectAroundCtor (e, ini, clo_ini);
//Check this usage before base()
//Allow this.field
//Deny base.*, this.method, this, base
@@ -1440,48 +1473,10 @@
List.Filter (l, seq) != []
}
_ = ctor_calls (e);
-
- }
- }
- when (is_ctor && !CurrentType.IsValueType)
- {
- def ini =
- match (CurrentType.init_list) {
- | [q]
- => match (q) {
- | PT.PExpr.Typed (e) => e
- | _ => Util.ice ("bad field initializers");
- }
- | _ => null
- };
- when (e == null)
- e = match (current_local_fun.body) {
- | FunBody.Typed (e) => e
- | _ => Util.ice ("bad function body")
- }
- when (clo_ini != null)
- {
- def f (_) {
- | TExpr.Call (e, _, _) when IsCtor (e) => Some (true)
- | _ => None ()
- }
- and ctor_calls (e) {
- SimpleFlow (e, f, false, seq, fork)
- }
- and seq (_) {
- | e :: _ => ctor_calls (e)
- | _ => false
- }
- and fork (l) {
- List.ForAll (l, seq)
- }
- when (!ctor_calls (e))
- Message.Error ("closure utilizing 'this' reference is not allowed when base ctor call is not placed at the beginning of current ctor");
- }
- e = InjectAroundCtor (e, ini, clo_ini);
current_local_fun.body = FunBody.Typed (e);
}
}
+ }
// the result is reversed!
Modified: nemerle/trunk/ncc/testsuite/negative/bug-664.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/negative/bug-664.n (original)
+++ nemerle/trunk/ncc/testsuite/negative/bug-664.n Fri Jul 6 22:58:54 2007
@@ -48,3 +48,10 @@
_ = this.y ();
}
}
+
+class C
+{
+ x : int { get; set; };
+ y : int = x; // E: using class method before base is constructed
+}
+
More information about the svn
mailing list