[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17566336#comment-17566336 ] ASF GitHub Bot commented on GROOVY-7971: eric-milles closed pull request #1269: GROOVY-7971: do not save instanceof types under logical or URL: https://github.com/apache/groovy/pull/1269 > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher >Priority: Major > Time Spent: 4h 10m > Remaining Estimate: 0h > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17317232#comment-17317232 ] Eric Milles commented on GROOVY-7971: - See also GROOVY-8965 > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher >Priority: Major > Time Spent: 4h 10m > Remaining Estimate: 0h > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian Jira (v8.3.4#803005)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16440025#comment-16440025 ] Paul King commented on GROOVY-7971: --- Giving a compiler STC error would be better - treating it as a Map we need to fix. > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher >Priority: Major > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16439919#comment-16439919 ] Jochen Theodorou commented on GROOVY-7971: -- I think it is ok to support only if the instanceof is used as part o the condition directly. Otherwise you will soon require to run the program to compile the program > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher >Priority: Major > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16439303#comment-16439303 ] Paul King commented on GROOVY-7971: --- A slightly simpler example: {code} import groovy.json.* import groovy.transform.* @CompileStatic class Bar { def meth(value) { Writer out = new StringWriter() def isString = value instanceof String //if (isString || value instanceof Map) { // (1) if (value instanceof String || value instanceof Map) { // (2) out.append(JsonOutput.toJson(value)) } out } } def writer = new Bar().meth('two') println writer.toString() {code} Here (2) works but (1) fails. > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher >Priority: Major > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15865311#comment-15865311 ] Paul King commented on GROOVY-7971: --- @blackdrag correct - the fact that {{value instanceof Map}} has been seen is recorded in {{typeCheckingContext.temporaryIfBranchTypeInformation}} regardless of the altering {{||}} expression > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian JIRA (v6.3.15#6346)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15580208#comment-15580208 ] Shil Sinha commented on GROOVY-7971: This only seems to happen for calls to type-overloaded methods e.g. JsonOutput#toJson. > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Commented] (GROOVY-7971) @CS flow typing incorrectly casting to map at runtime
[ https://issues.apache.org/jira/browse/GROOVY-7971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15575793#comment-15575793 ] Jochen Theodorou commented on GROOVY-7971: -- I assume that the compiler only check for "instanceof Map" and fails to see, that it is not the only condition here > @CS flow typing incorrectly casting to map at runtime > - > > Key: GROOVY-7971 > URL: https://issues.apache.org/jira/browse/GROOVY-7971 > Project: Groovy > Issue Type: Bug >Affects Versions: 2.4.7 >Reporter: Graeme Rocher > > The following code: > {code} > import groovy.json.* > import groovy.transform.* > @CompileStatic > class Bar { > private Writable renderTemplate(Object o, Map args) { > > } > private boolean isSimpleType(Class type) { > return type == String > } > def foo(Map map, Map arguments) { > > def writable = new Writable() { > @Override > Writer writeTo(Writer out) throws IOException { > for(entry in map.entrySet()) { >def value = entry.value >if(isSimpleType(value.getClass()) || (value instanceof > Map)) { > out.append(JsonOutput.toJson(value)) > } > } > return out > } > } > } > } > writable = new Bar().foo([one:'two'],[foo:'bar']) > sw = new StringWriter() > writable.writeTo(sw) > println sw > {code} > Fails with: > {code} > org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast > object 'two' with class 'java.lang.String' to class 'java.util.Map' > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319) > at > org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232) > > {code} > For some reason Groovy is attempting to cast value to Map when it isn't one. -- This message was sent by Atlassian JIRA (v6.3.4#6332)