[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
Tue Mar 7 21:15:34 CET 2006


A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=633> 
======================================================================
Reported By:                amp
Assigned To:                
======================================================================
Project:                    Nemerle
Issue ID:                   633
Category:                   The Language
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
======================================================================
Date Submitted:             03-06-2006 01:13 CET
Last Modified:              03-07-2006 21:15 CET
======================================================================
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.

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                          
======================================================================




More information about the bugs mailing list