[nem-bug] [Nemerle 0000633]: You cannot overload += or other operators that are defined as macros in macros/operators.n

feedback at nemerle.org feedback at nemerle.org
Mon May 22 18:05:22 CEST 2006


The following issue has been CLOSED
======================================================================
<http://nemerle.org/bugs/view.php?id=633> 
======================================================================
Reported By:                amp
Assigned To:                nazgul
======================================================================
Project:                    Nemerle
Issue ID:                   633
Category:                   The Language
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     closed
Resolution:                 not an issue
Fixed in Version:           
======================================================================
Date Submitted:             03-06-2006 01:13 CET
Last Modified:              05-22-2006 18:05 CEST
======================================================================
Summary:                    You cannot overload += or other operators that are
defined as macros in macros/operators.n
Description: 
Because the macro is applied before the user defined operators are applied,
the overload is silently ignored.

++ and -- are overloadable, but cannot be applied to immutable variables
because the macro performs an assignment.

I think it is important to allow an arbitrary function to be called by any
operator, because it allows programs to define mini-languages that operate
among a group of classes.

That being said, this issue should at least be documented. 

The operators effected are:
&&, ||, %||, %&&, %^^, ++, --, +=, -=, *=, /=, <<=, >>=, %=, |=, &=, ^=,
<->, ::=

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

----------------------------------------------------------------------
 nazgul - 03-07-06 19:32 
----------------------------------------------------------------------
AFAIR this is just like in C# and it is quite good design - all those
operators are (and should remain) shortcuts for a longer, more verbose
assignment expressions. So you can overload + operator and compiler will
automatically make ++ +=, etc. operators work as expected with this.

Of course, this is a restriction, but sometimes compiler should force
consistent and sane design on developer :)

----------------------------------------------------------------------
 malekith - 03-07-06 19:46 
----------------------------------------------------------------------
But I guess a different mechanism is used for ++/-- in C#.

----------------------------------------------------------------------
 nazgul - 03-07-06 19:53 
----------------------------------------------------------------------
Especially with stange special case in int->short conversions ;)

----------------------------------------------------------------------
 amp - 03-07-06 21:15 
----------------------------------------------------------------------
That is very reasonable. So I guess this should be considered a bug in the
documentation. The docs should be clear about this. I'll try to compose
something to add to the Operators page and some of the Operator
Overloading sections on various pages on the Wiki. Or should I leave that
to someone more qualified?

Also could the compiler issue a warning when people create an operator
with the same name as a macro? Because the macro will always shadow the
operator and the programmer will have to way to know this unless they are
looking for it.

----------------------------------------------------------------------
 amp - 04-01-06 07:28 
----------------------------------------------------------------------
I added some documentation about this to
http://nemerle.org/Nemerle_for_OOP_Programmers_Week_5 and
http://nemerle.org/Operators

I think that may close this issue. But that's up to you of course.

----------------------------------------------------------------------
 nazgul - 04-01-06 10:05 
----------------------------------------------------------------------
Thanks, that is fine. So the issue is resolved.

Issue History
Date Modified  Username       Field                    Change              
======================================================================
03-06-06 01:13 amp            New Issue                                    
03-06-06 03:17 amp            Issue Monitored: amp                         
03-07-06 19:32 nazgul         Note Added: 0001115                          
03-07-06 19:46 malekith       Note Added: 0001116                          
03-07-06 19:53 nazgul         Note Added: 0001117                          
03-07-06 21:15 amp            Note Added: 0001119                          
04-01-06 07:28 amp            Note Added: 0001132                          
04-01-06 10:05 nazgul         Status                   new => resolved     
04-01-06 10:05 nazgul         Resolution               open => not an issue
04-01-06 10:05 nazgul         Assigned To               => nazgul          
04-01-06 10:05 nazgul         Note Added: 0001134                          
04-01-06 10:05 nazgul         Description Updated                          
05-22-06 18:05 nazgul         Status                   resolved => closed  
======================================================================




More information about the bugs mailing list