Boo
  1. Boo
  2. BOO-79

use implicit conversion operators

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      0

      Description

      A lot of types in the BCL (System.Decimal for instance) define implicit and explict conversion operators [1].

      Those operators should be used by boo as apropriate for assignments, function argument evaluation (including overloaded operators) and cast expressions.

      More explicitly, the following boo program:

      def x2(value as Decimal):
      return value*2

      print(x2(4))
      d as Decimal = 0

      should be interpreted as:

      def x2(value as Decimal):
      return Decimal.op_Multiply(value, Decimal.op_Implicit(2))

      print(x2(Decimal.op_Implicit(4)))
      d as Decimal = Decimal.op_Implicit(0)

      [1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_10_9_3.asp

        Issue Links

          Activity

          Rodrigo B. de Oliveira made changes -
          Field Original Value New Value
          Fix Version/s 0.4 [ 10961 ]
          Rodrigo B. de Oliveira made changes -
          Fix Version/s 0.4 [ 10961 ]
          Fix Version/s 0.5 [ 10963 ]
          Rodrigo B. de Oliveira made changes -
          Fix Version/s 0.5 [ 10963 ]
          Fix Version/s 0.6 [ 11022 ]
          Rodrigo B. de Oliveira made changes -
          Link This issue is duplicated by BOO-362 [ BOO-362 ]
          Doug H made changes -
          Link This issue is related to BOO-206 [ BOO-206 ]
          Doug H made changes -
          Attachment opimplicit1.patch [ 17296 ]
          Rodrigo B. de Oliveira made changes -
          Fix Version/s 0.7.5 [ 12052 ]
          Fix Version/s 0.7.6 [ 12110 ]
          Doug H made changes -
          Link This issue is related to BOO-651 [ BOO-651 ]
          Doug H made changes -
          Comment [ I changed ProcessMethodBodies.FindConversionOperator to the below code. A test is below that.


          IMethod FindConversionOperator(string name, IType fromType, IType toType)
          {
          IType origType = fromType;
          while (fromType != TypeSystemServices.ObjectType)
          {
          foreach (IEntity entity in fromType.GetMembers())
          {
          if (EntityType.Method == entity.EntityType &&
          name == entity.Name)
          {
          IMethod method = (IMethod)entity;
          if (IsConversionOperator(method, fromType, toType))
          {
          return method;
          }
          }
          }
          fromType = fromType.BaseType;
          if (null == fromType) break;
          }
          fromType = origType;
          origType = toType;
          while (toType != TypeSystemServices.ObjectType)
          {
          foreach (IEntity entity in toType.GetMembers())
          {
          if (EntityType.Method == entity.EntityType &&
          name == entity.Name)
          {
          IMethod method = (IMethod)entity;
          if (IsConversionOperator(method, fromType, toType))
          {
          return method;
          }
          }
          }
          toType = toType.BaseType;
          if (null == toType) break;
          }
          return null;
          }

          //////////////////////////////////////////////////////////////////////

          import System
          import System.Runtime.InteropServices

          obj = object()

          //succeeds:
          ptr as IntPtr = cast(IntPtr, GCHandle.Alloc( obj ))

          //previously failed:
          gch = cast(GCHandle, ptr)

          //should fail because op_Explicit requires explicit cast:
          //gch2 as GCHandle = ptr

          print gch
          ]
          Doug H made changes -
          Attachment opimplicit5.patch [ 19248 ]
          Doug H made changes -
          Attachment opimplicit5.patch [ 19248 ]
          Doug H made changes -
          Attachment opimplicit6.patch [ 19257 ]
          Doug H made changes -
          Attachment opimplicit6.patch [ 19257 ]
          Doug H made changes -
          Attachment opimplicit7.patch [ 19258 ]
          Doug H made changes -
          Link This issue is depended upon by BOO-223 [ BOO-223 ]
          Doug H made changes -
          Attachment opimplicit7.patch [ 19258 ]
          Doug H made changes -
          Fix Version/s 0.7.6 [ 12110 ]
          Resolution Won't Fix [ 2 ]
          Status Open [ 1 ] Closed [ 6 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Rodrigo B. de Oliveira
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: