Menu

zinc doesn't upcast objects

Mark Ng
2005-02-06
2013-04-26
  • Mark Ng

    Mark Ng - 2005-02-06

    consider this code:
    import "text/string-buffer"
    struct strbuf: local string buffer  // why is local required ?
      ...
    end

    public equ @shl (s: strbuf, c: int) = str append(s,c)

    def s = new strbuf
    s << "answer:" << 42  // calls the parent's method, not child's 'str append'

    Is this a bug or a feature ?  Shouldn't the child's method  have precedence.

     
    • Marc Kerbiquet

      Marc Kerbiquet - 2005-02-07

      The type of (s << "answer:") is 'string buffer', so it calls the parent method for ((s << "answer:") << 42). The types of expressions are resolved at compile time, not at run time.

      About 'local'
      struct strbuf: local string buffer
        ...
      end
      is somewhat equivalent to:
      struct strbuf
        super: local string buffer
        ...
      end
      hence the 'local'

       
    • Mark Ng

      Mark Ng - 2005-02-08

      >> The type of (s << "answer:") is 'string buffer', so it calls the parent method for ((s << "answer:") << 42). The types of expressions are resolved at compile time, not at run time.

      Yes, that is what I meant when I said that zinc doesn't upcast. :)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.