jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-1959

Can't use GStrings as map keys

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

GStrings seemingly can't be used as map keys. The error seems to be generated by the GString not being able to be converted to a string.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Russel Winder added a comment - 29/Jun/07 3:58 AM

This is not really true as stated since:

someString = 'blah'

def someFunction ( a ) {
  println ( a.toString ( ) )
  return a.toString ( )
}

assert someFunction ( datum : 'A String.' ) ==  '{datum=A String.}'
assert someFunction ( ( someString ) : 'A String.' ) == '{blah=A String.}'
assert someFunction ( 'aString' : 'A String.' ) == '{aString=A String.}'
assert someFunction ( "X${someString}" : 'A GString.' ) == '{Xblah=A GString.}'

appears to work fine. This issue arises originally from a problem in Gant, so it seems this may actually be a problem in the treatment of parameters in the target/task closure in gant.Gant rather than a Groovy problem.

Show
Russel Winder added a comment - 29/Jun/07 3:58 AM This is not really true as stated since:
someString = 'blah'

def someFunction ( a ) {
  println ( a.toString ( ) )
  return a.toString ( )
}

assert someFunction ( datum : 'A String.' ) ==  '{datum=A String.}'
assert someFunction ( ( someString ) : 'A String.' ) == '{blah=A String.}'
assert someFunction ( 'aString' : 'A String.' ) == '{aString=A String.}'
assert someFunction ( "X${someString}" : 'A GString.' ) == '{Xblah=A GString.}'
appears to work fine. This issue arises originally from a problem in Gant, so it seems this may actually be a problem in the treatment of parameters in the target/task closure in gant.Gant rather than a Groovy problem.
Hide
Permalink
Russel Winder added a comment - 15/Jul/07 1:23 AM

As blackdrag pointed out on the mail lists, it is not clear that unevaluated GStrings make sensible map keys – the problem is that the key is variable not constant, so it is not clear that the key can ever be found during lookup.

So although GStrings can appear as map keys, it makes far more sense to say that keys should be constant so instead of using:

"X${someString}"

use

'X' + someString

to enforce evaluation to a constant string.

It is not clear to me how or whether to progress this issue or just declare it to be a non-issue.

Show
Russel Winder added a comment - 15/Jul/07 1:23 AM As blackdrag pointed out on the mail lists, it is not clear that unevaluated GStrings make sensible map keys – the problem is that the key is variable not constant, so it is not clear that the key can ever be found during lookup. So although GStrings can appear as map keys, it makes far more sense to say that keys should be constant so instead of using:
"X${someString}"
use
'X' + someString
to enforce evaluation to a constant string. It is not clear to me how or whether to progress this issue or just declare it to be a non-issue.
Hide
Permalink
Russel Winder added a comment - 15/Jul/07 1:24 AM

Lowering the priority since it is not clear there is actually a problem here to be solved.

Show
Russel Winder added a comment - 15/Jul/07 1:24 AM Lowering the priority since it is not clear there is actually a problem here to be solved.
Hide
Permalink
Luke Daley added a comment - 15/Jul/07 7:47 AM

I think it would be fine to close this. It is technically a bug, but I don't think it is worth spending the effort on. You may want to add something to the Gant documentation saying that you can't use GStrings for target names. Not sure how often it would come up, but it would be a frustrating sort of issue to try and work out for a user not on the mailing lists and such.

Show
Luke Daley added a comment - 15/Jul/07 7:47 AM I think it would be fine to close this. It is technically a bug, but I don't think it is worth spending the effort on. You may want to add something to the Gant documentation saying that you can't use GStrings for target names. Not sure how often it would come up, but it would be a frustrating sort of issue to try and work out for a user not on the mailing lists and such.
Hide
Permalink
Russel Winder added a comment - 17/Jul/07 1:10 AM

Comment added to http://groovy.codehaus.org/Gant_Tasks

Show
Russel Winder added a comment - 17/Jul/07 1:10 AM Comment added to http://groovy.codehaus.org/Gant_Tasks

People

  • Assignee:
    Russel Winder
    Reporter:
    Luke Daley
Vote (0)
Watch (0)

Dates

  • Created:
    29/Jun/07 3:22 AM
    Updated:
    28/Oct/07 5:11 AM
    Resolved:
    28/Oct/07 5:11 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.