[ 
https://issues.apache.org/jira/browse/GROOVY-12454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18131619#comment-18131619
 ] 

ASF GitHub Bot commented on GROOVY-12454:
-----------------------------------------

paulk-asert commented on PR #3013:
URL: https://github.com/apache/groovy/pull/3013#issuecomment-6390405453

   Thanks Daniel.
   
   1. Checked: #3000 and #3013 merge without conflict. The constant-key guard 
from #3000 ends up in the literal-map setProperties here, so literal keys keep 
the direct setter. Groovy12456, ConstructorsSTCTest and 
StaticCompileConstructorsTest all pass on the merged tree.
   2. Agreed: for a non-literal map the entries are only known at runtime, so 
an unknown key is a MissingPropertyException at runtime, as in dynamic Groovy 
(covered by the bad-key test).
   4. A null key NPEs identically in dynamic mode: MetaClassImpl.setProperties 
also calls entry.getKey().toString().
   5. Confirmed: STC only uses the synthetic map constructor when no declared 
constructor accepts the arguments, and the transformer still falls back for a 
declared target. A class with both C() and C(Map) uses the declared C(Map) 
under SC, as it does dynamically.




> "Target constructor for constructor call expression hasn't been set" when 
> using map-constructor-call with method-returned map under static compilation
> ------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12454
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12454
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.23, 3.0.25, 5.0.3, 4.0.33, 5.1.3, 6.0.0
>            Reporter: Björn Kautler
>            Priority: Major
>
> Given the snippet
> {code:groovy}
> class Person2 {
>   def name
>   def age
> }
> def <T> T record(T value) {
>   value
> }
> Map recordMap(Map value) {
>   value
> }
> @groovy.transform.CompileStatic
> def foo() {
>   [
>     new Person2(record([name: 'fred', age: 25])),
>     new Person2([name: 'fred', age: 25]),
>     new Person2(recordMap([name: 'fred', age: 25]))
>   ]
> }
> foo() {code}
>  
> With the {{CompileStatic}} line commented out, all versions mentioned as 
> affected compile fine and run fine, returning a list with three identical 
> person instances with the properties set.
> With the snippet as given, none of the versions can compile the snippet due 
> to the first and last constructor lines.
> Except of 3.0.25 all versions tell for both lines "Target constructor for 
> constructor call expression hasn't been set".
> 3.0.25 shows the same for the first one, and "Cannot find matching method 
> Person2#<init>(java.util.Map). Please check if the declared type is correct 
> and if the method exists." for the last one.
> With {{TypeChecked}} instead of {{CompileStatic}} it also works fine in all 
> versions except 3.0.25. 3.0.25 with only type-checke can compile the first 
> line but still has the same error for the last line.z
>  
> So it seems the SC does not properly use the "map-constructor-call" semantics 
> if a normal or generic method call returned type {{{}Map{}}}, plus 3.0.25 
> having some additional problem.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to