[nem-bug] [Nemerle 0000698]: [0.9.3] Extension methods not visible on nested types

feedback at nemerle.org feedback at nemerle.org
Fri Jun 30 20:30:46 CEST 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=698> 
======================================================================
Reported By:                Snaury
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   698
Category:                   Compiler
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             06-30-2006 20:04 CEST
Last Modified:              06-30-2006 20:30 CEST
======================================================================
Summary:                    [0.9.3] Extension methods not visible on nested
types
Description: 
Example code:

#pragma indent

public module Outer
  public module Inner
    public test(this o : object) : void
      System.Console.WriteLine("test calle on object: {0}", o.ToString())

using Outer.Inner

public module Program
  public Main() : void
    def o = System.Object()
    o.test() // error: there is no member named `test' in System.Object
with type ?
======================================================================

----------------------------------------------------------------------
 Snaury - 06-30-06 20:10 
----------------------------------------------------------------------
Ah, sorry, the correct code is this:

#pragma indent

public module Outer
  public module Inner
    public test(this o : object) : void
      System.Console.WriteLine("test calle on object: {0}", o.ToString())

    public test2(o : object) : void
      o.test() // *** error here ***

using Outer

public module Program
  public test3(this o : object) : void
    o.test() // no error

  public Main() : void
    def o = System.Object()
    o.test() // no error
    o.test3() // no error

----------------------------------------------------------------------
 nazgul - 06-30-06 20:14 
----------------------------------------------------------------------
This is because in Outer, Inner is not 'opened'. If you declare using
Outer.Inner;  at the top of the file, it should work.

----------------------------------------------------------------------
 Snaury - 06-30-06 20:21 
----------------------------------------------------------------------
Hmm, then it seems more like in Inner Outer is not opened (which is
strange, I can call static methods from Outer, why not extensions? see my
comment where I posted corrected code so that test becomes visible in
Program.Main, but is not visible in Inner itself). Anyway, using Outer at
the top of the file works, thanks for the reply!

----------------------------------------------------------------------
 Snaury - 06-30-06 20:30 
----------------------------------------------------------------------
This code shows it even better:

#pragma indent

// when using commented here...
using Outer

public module Outer
  public test_from_outer(this o : object) : void
    System.Console.WriteLine("test_from_outer called on object: {0}",
o.ToString())

  public test(o : object) : void
    o.test_from_outer()

  public module Inner
    public test_from_inner(this o : object) : void
      System.Console.WriteLine("test_from_inner called on object: {0}",
o.ToString())

    public test(o : object) : void
      o.test_from_outer()
      o.test_from_inner() // ***

// ...and uncommented here, will give error in line marked with ***
// using Outer

public module Program
  public test_from_program(this o : object) : void
    o.test_from_outer()
    o.test_from_inner()

  public Main() : void
    def o = System.Object()
    o.test_from_program()

To me it seems kind of confusing, because I assume that contents of Outer
is already visible to Inner. But anyway, if that's by design, then I guess
it's ok, just a little confusing...

Issue History
Date Modified  Username       Field                    Change              
======================================================================
06-30-06 20:04 Snaury         New Issue                                    
06-30-06 20:10 Snaury         Note Added: 0001325                          
06-30-06 20:14 nazgul         Note Added: 0001326                          
06-30-06 20:21 Snaury         Note Added: 0001327                          
06-30-06 20:30 Snaury         Note Added: 0001328                          
======================================================================




More information about the bugs mailing list