[nem-bug] [Nemerle 0000664]: Usage of 'this' reference should be controlled before call to base ctor

feedback at nemerle.org feedback at nemerle.org
Sat May 5 15:40:30 CEST 2007


The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=664> 
======================================================================
Reported By:                nazgul
Assigned To:                divan
======================================================================
Project:                    Nemerle
Issue ID:                   664
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     resolved
Resolution:                 fixed
Fixed in Version:           
======================================================================
Date Submitted:             05-07-2006 13:53 CEST
Last Modified:              05-05-2007 15:40 CEST
======================================================================
Summary:                    Usage of 'this' reference should be controlled
before call to base ctor
Description: 
class Base {
  public this (_ : Base) { 
  } 
}

class Inh : Base {
 
  public this () {
    base (this)
  }
  
}

()

causes verification error:
[IL]: Error: [C:\cygwin\home\nazgul\nemerle\ncc\testsuite\out.exe :
Inh::.ctor][offset 0x00000002][found <uninitialized> ref ('this' ptr)
'Inh'][expected ref 'Base'] Unexpected type on the stack.

======================================================================

----------------------------------------------------------------------
 akhropov - 10-06-06 18:38 
----------------------------------------------------------------------
I believe it should also be prohibited to access base and its members
before its constructor is called because logically speaking base object
doesn't exist before its constructor is called.

However,  the following code compiles just fine at the moment:

class A
{
	internal x : int;
	public this( x : int = 10 )
	{
		this.x = x;
	}
}

class B : A
{
	public this()
	{
		System.Console.WriteLine($"base.x = $(base.x)");
		base( 1 );
	}
}

def b = B();
System.Console.WriteLine(b);

----------------------------------------------------------------------
 nazgul - 01-05-07 20:44 
----------------------------------------------------------------------
One more example we now handle incorrectly:

abstract class A {
   protected this (x : string) {
     assert (x != null);   
   }
}

class B : A {
   mutable a : string = "asa";
   public this () {
     base (a);    
   }
}


Actually, the initializer is executed AFTER base ctor call, so NPE is
thrown in base. In C# equivalent code is not allowed, because it does now
allow passing instance field values to base call (this is actually
consequence of disallowing usage of 'this' reference)

----------------------------------------------------------------------
 divan - 04-10-07 21:28 
----------------------------------------------------------------------
Last one example works on r7588, fields are initialized before base() call
now.

----------------------------------------------------------------------
 divan - 05-05-07 15:40 
----------------------------------------------------------------------
Fixed on r7656.

Case with closures is still a todo, attached to 976.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
05-07-06 13:53 nazgul         New Issue                                    
10-06-06 18:38 akhropov       Note Added: 0001468                          
01-05-07 20:44 nazgul         Note Added: 0001600                          
04-10-07 21:28 divan          Note Added: 0001841                          
04-22-07 13:13 divan          Issue Monitored: divan                       
05-05-07 15:40 divan          Note Added: 0001877                          
05-05-07 15:40 divan          Assigned To               => divan           
05-05-07 15:40 divan          Status                   new => resolved     
05-05-07 15:40 divan          Resolution               open => fixed       
05-05-07 15:40 divan          Summary                  Usage of 'this' reference
should be controlled before call to base ctor => Usage of \'this\' reference
should be controlled before call to base ctor
05-05-07 15:40 divan          Description Updated                          
05-05-07 15:40 divan          Additional Information Updated                    
======================================================================




More information about the bugs mailing list