[nem-bug] [Nemerle 0000776]: Can't Define virtual & override methods (in macro)

feedback at nemerle.org feedback at nemerle.org
Sun Oct 8 16:05:43 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=776> 
======================================================================
Reported By:                VladD2
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   776
Category:                   Compiler (type engine)
Reproducibility:            always
Severity:                   block
Priority:                   urgent
Status:                     new
======================================================================
Date Submitted:             10-05-2006 01:59 CEST
Last Modified:              10-08-2006 16:05 CEST
======================================================================
Summary:                    Can't Define virtual & override methods (in macro)
Description: 
Macro code:
----------------------------------------------------------------------------
using Nemerle.Compiler;

[Nemerle.MacroUsage (Nemerle.MacroPhase.WithTypedMembers,
                     Nemerle.MacroTargets.Class)]
macro AddVirtualTestImpl (tb : TypeBuilder)
{
  tb.Define (<[ decl: 
    internal virtual TestImpl () : void
    {
    }
  ]>);
}

[Nemerle.MacroUsage (Nemerle.MacroPhase.WithTypedMembers,
                     Nemerle.MacroTargets.Class)]
macro AddOverrideTestImpl (tb : TypeBuilder)
{
  tb.Define (<[ decl: 
    internal override TestImpl () : void
    {
    }
  ]>);
}
----------------------------------------------------------------------------
Code use macro:
----------------------------------------------------------------------------
[AddVirtualTestImpl]
class A { }

[AddOverrideTestImpl]
class B : A { }
----------------------------------------------------------------------------
Error message:
----------------------------------------------------------------------------
Main.n(4,2,4,21): error : `override' specified on method B.TestImpl() :
void, but there is no such member in parent to override
======================================================================

----------------------------------------------------------------------
 malekith - 10-05-06 07:46 
----------------------------------------------------------------------
It's by design.

You need to add virtual memebers in the BeforeInheritance stage, not
WithTypedMembers. Otherwise they are not visible in derived class.

We can maybe turn this issue into feature request to allow this also at
later stages. Is BeforeInheritenance a problem for you?

----------------------------------------------------------------------
 nazgul - 10-08-06 15:51 
----------------------------------------------------------------------
I agree, we do not allow adding virtual members during WithTypedMembers
stage. Changing this would require lots of refactoring of "override" and
virtual methods handling.
And the solution is quite simple - just add virtual members in
BeforeTypedMembers stage.

----------------------------------------------------------------------
 VladD2 - 10-08-06 15:55 
----------------------------------------------------------------------
I cannot add methods at stage BeforeInheritance. I need use
TypeBuilder.GetFields() method to determinate what classes require
methods.

What problem add methods into TypeInfo.member_map (of subtypes) during
adding it in supertype?

----------------------------------------------------------------------
 VladD2 - 10-08-06 16:03 
----------------------------------------------------------------------
If I simply comment this lines:
        | None =>
          //when (mem.Attributes %&& NemerleAttributes.Override)
          //{
          //  Message.Error ($"`override' specified on $mem, "
          //                 "but there is no such member in parent to
override");
          //}

...then my code compile successfully. May be add in this point simple hack
(add member to member_map if it exists in one of supertype)?

----------------------------------------------------------------------
 nazgul - 10-08-06 16:05 
----------------------------------------------------------------------
Adding methods in given class changes the way how interfaces are
implemented in derived classes and how all the checks are performed for
overriding methods - we would need to re-process all existing methods in
subclasses to validate that everything is still ok. Not mentioning such
problems, like finding all deriving classes from given one.

Can you use parsed version of fields, instead of list of FieldBuilders
from GetFields? In BeforeTypedMembers you can simply analyze the parse
tree of class.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
10-05-06 01:59 VladD2         New Issue                                    
10-05-06 07:46 malekith       Note Added: 0001467                          
10-08-06 15:51 nazgul         Note Added: 0001469                          
10-08-06 15:55 VladD2         Note Added: 0001470                          
10-08-06 16:03 VladD2         Note Added: 0001471                          
10-08-06 16:05 nazgul         Note Added: 0001472                          
======================================================================




More information about the bugs mailing list