[nem-bug] [Nemerle 0000759]: multiple type conversion operators

feedback at nemerle.org feedback at nemerle.org
Fri Nov 10 19:27:22 CET 2006


The following issue has been RESOLVED.
======================================================================
<http://nemerle.org/bugs/view.php?id=759> 
======================================================================
Reported By:                aleksey
Assigned To:                nazgul
======================================================================
Project:                    Nemerle
Issue ID:                   759
Category:                   Compiler
Reproducibility:            always
Severity:                   feature
Priority:                   normal
Status:                     resolved
Resolution:                 fixed
Fixed in Version:           
======================================================================
Date Submitted:             09-21-2006 00:36 CEST
Last Modified:              11-10-2006 19:27 CET
======================================================================
Summary:                    multiple type conversion operators
Description: 
C# allows multiple implicit or explicit cast operators to be defined.
ncc however doesn't treat cast operators as a special case and reports
with "attempted return type overload" error, though it works fine with
several conversions defined in externally referenced types.

I am not sure whether this is by design or something else. It was easy to
tweak compiler a little and add this feature. I've included a patch,
though I am not sure it is the most elegant and correct solution(at least
it seems to work). Patch also enables return type overloading, by
replacing error message with warning, so you probably would not like to
apply it as is. Btw, am I right that prohibiting return type overloads was
a design decicion, not a limitation(as it seems to work pretty fine)?
======================================================================

----------------------------------------------------------------------
 malekith - 09-23-06 09:58 
----------------------------------------------------------------------
The right way to do it, would be to special-case cast operator and not to
issue error message in this case.

As for the general return type overloading -- it was a design decision.
There are two reasons. The first one is that CLS doesn't allow that (so no
other language could use such functions). The second one is that type
inference will have a much harder time guessing the right types in
presence of return type overloads. Also at the time the decision was made,
the type inference algorithm was much weaker than it is now.

----------------------------------------------------------------------
 aleksey - 09-23-06 10:19 
----------------------------------------------------------------------
Well, that's what my patch is doing. Just replace warning with error
message in my code, so return type overloading will not work(I enabled it
just for experimentation purposes) and cast operators will be a
special-case and thus will not issue error message.

----------------------------------------------------------------------
 malekith - 09-23-06 11:00 
----------------------------------------------------------------------
Sorry, I was confused. I don't think your test for op_Implicit&co is a
hack, I think it is fine.

Please commit! (with error and not a warning)

It would be also great to have a little testcase (just add two lines in
one of the test files).

----------------------------------------------------------------------
 nazgul - 11-10-06 19:27 
----------------------------------------------------------------------
Fixed on trunk (r6862). Thanks for a patch.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
09-21-06 00:36 aleksey        New Issue                                    
09-21-06 00:36 aleksey        File Added: multiple_cast_operators.patch         
          
09-23-06 09:58 malekith       Note Added: 0001452                          
09-23-06 10:19 aleksey        Note Added: 0001453                          
09-23-06 11:00 malekith       Note Added: 0001454                          
11-10-06 19:27 nazgul         Status                   new => resolved     
11-10-06 19:27 nazgul         Resolution               open => fixed       
11-10-06 19:27 nazgul         Assigned To               => nazgul          
11-10-06 19:27 nazgul         Note Added: 0001502                          
======================================================================




More information about the bugs mailing list