Boo
  1. Boo
  2. BOO-1300

Automatically make a constructor() in global scope static

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 0.9.5
    • Component/s: Compiler
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      when to define constructor() in global scope,
      I think that the compiler should report an error then.

      ---sample code---

      1. the code has a bug purposely

      class Rectangle:
      _width as single
      _height as single
      def constructor(width as single, height as single):
      _width = width
      _height = height

      virtual def GetArea():
      return _width * _height

      class Square(Rectangle):
      def constructor(width as single):
      super(width, width)

      override def GetArea():
      return _width * _width

      ----compile it----
      >booc constructor.boo
      Boo Compiler version 0.9.2.3383 (CLR 2.0.50727.4200)
      constructor.boo(14,14): BCE0024: The type 'Rectangle' does not have a visible constructor
      that matches the argument list '(single, single)'.
      constructor.boo(16,18): BCE0060: 'Square.GetArea()': no suitable method found to override.

      constructor.boo(9,16): BCE0005: Unknown identifier: '_width'.
      constructor.boo(9,25): BCE0005: Unknown identifier: '_height'.
      4 error(s).

        Activity

        Hide
        rektide added a comment -

        am talking with kanryu in irc.
        samples a little complex, heres a much easier example:

        def constructor():
        	print("constructor")
        
        print("main")
        

        there's not really any way to access this constructor, should probably through an error since its "dead code."

        Show
        rektide added a comment - am talking with kanryu in irc. samples a little complex, heres a much easier example: def constructor(): print("constructor") print("main") there's not really any way to access this constructor, should probably through an error since its "dead code."
        Hide
        Cedric Vivier added a comment -

        I don't think this should be an error, it should be converted automatically as a static constructor for the module.
        Currently methods at global scope are automatically static so constructors should behave the same imo.

        Currently, following :

        static def constructor():
        	print("constructor")
        
        print("main")
        

        would work as intended.

        Show
        Cedric Vivier added a comment - I don't think this should be an error, it should be converted automatically as a static constructor for the module. Currently methods at global scope are automatically static so constructors should behave the same imo. Currently, following : static def constructor(): print( "constructor" ) print( "main" ) would work as intended.

          People

          • Assignee:
            Unassigned
            Reporter:
            KATO Kanryu
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: