Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-813

no assignments to literals

    XMLWordPrintableJSON

Details

    Description

      Definitely! Whether we can do this inside the Antlr grammar, or we add
      a validation check to the Groovy AST verifier (which has a few checks
      in it already) I don't much mind, but we definitely need to outlaw
      these examples.

      On 9 Apr 2005, at 13:21, Dierk Koenig wrote:
      > Currently Groovy allows
      >
      > 'aaa' = 'bbb'
      > "aaa" = "bbb"
      > /aaa/ = /bbb/
      > null = new Object()
      > 0 = 1
      > 0f = 1f
      > \u0000 = \u0001
      >
      > // questionable
      > [] = new Object()
      > [:] = new Object()
      > 1..2 = new Object()
      >
      > this makes it harder to write safe boolean tests, e.g.
      > if (null == a)
      > instead of
      > if (a == null)
      > to mitigate the risk of a missing =, e.g
      > if (null = a)
      > should not compile.
      >
      > I think this should be possible by changing
      > only the grammar file.
      >
      > cheers
      > Mittie
      >
      >

      James
      -------
      http://radio.weblogs.com/0112098/

      Attachments

        Activity

          People

            jstrachan James Strachan
            codevise Dierk König
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: