Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[toolbox] Cannot invoke Java vararg constructor #9212

Closed
scabug opened this issue Mar 11, 2015 · 3 comments
Closed

[toolbox] Cannot invoke Java vararg constructor #9212

scabug opened this issue Mar 11, 2015 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Mar 11, 2015

// JavaVarArg.java
package debug;

public class JavaVarArg {
	private Integer[] args;
	
	public JavaVarArg(Integer... args) {
		this.args = args;
	}
	
	public String toString() {
		return "JavaVarArg(" + java.util.Arrays.toString(args) + ")";
	}
}
> console                                                                                                             
[info] Starting scala interpreter...                                                                                  
[info]                                                                                                                
import scala.reflect.runtime.universe._                                                                               
import scala.tools.reflect.ToolBox                                                                                    
toolbox: scala.tools.reflect.ToolBox[reflect.runtime.universe.type] = scala.tools.reflect.ToolBoxFactory$ToolBoxImpl@1
535688c                                                                                                               
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).                                   
Type in expressions to have them evaluated.                                                                           
Type :help for more information.                                                                                      
                                                                                                                      
scala> toolbox.typecheck(toolbox.parse("new debug.JavaVarArg(1)"))                                                    
scala.tools.reflect.ToolBoxError: reflective typecheck has failed: type mismatch;                                     
 found   : Int(1)                                                                                                     
 required: Array[Integer]                                                                                             
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$typecheck$1.apply(ToolBoxFactory.scala:178)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$typecheck$1.apply(ToolBoxFactory.scala:170)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$11.apply(ToolBoxFactory.scala:148)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$11.apply(ToolBoxFactory.scala:148)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$9.apply(ToolBoxFactory.scala:138)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$9.apply(ToolBoxFactory.scala:138)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$withContext$1$1.apply(ToolBoxFactory.scala:139)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$withContext$1$1.apply(ToolBoxFactory.scala:139)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$7.apply(ToolBoxFactory.scala:137)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1$$anonfun$7.apply(ToolBoxFactory.scala:137)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1.apply(ToolBoxFactory.scala:148)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal$$anonfun$transformDuringTyper$1.apply(ToolBoxFactory.scala:121)
  at scala.reflect.internal.Trees$class.wrappingIntoTerm(Trees.scala:1691)                                            
  at scala.reflect.internal.SymbolTable.wrappingIntoTerm(SymbolTable.scala:16)                                        
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.withWrapping$1(ToolBoxFactory.scala:120)            
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.transformDuringTyper(ToolBoxFactory.scala:121)      
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.typecheck(ToolBoxFactory.scala:169)                 
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$typecheck$2.apply(ToolBoxFactory.scala:375)              
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$typecheck$2.apply(ToolBoxFactory.scala:367)              
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.liftedTree2$1(ToolBoxFactory.scala:355)          
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:355)                  
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.typecheck(ToolBoxFactory.scala:367)                               
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.typecheck(ToolBoxFactory.scala:27)                                
  ... 43 elided                                                                                                       
                                                                                                                      
scala>                                                                                                           
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 11, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9212?orig=1
Reporter: Jerzy Muller (keros)
Affected Versions: 2.11.4

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Mar 11, 2015

Jerzy Muller (keros) said:
Standard java vararg methods works:

scala> toolbox.typecheck(toolbox.parse("java.util.Arrays.asList(1,2,3)"))
res2: toolbox.u.Tree = java.util.Arrays.asList[Int](1, 2, 3)
@scabug scabug closed this Jun 17, 2015
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 19, 2015

@scabug scabug added this to the 2.11.7 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.