[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 19:53:30 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 19:53 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 ;)

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




More information about the bugs mailing list