2013-04-15 8 views
7

पहनना पड़ता है मैं निम्नलिखित जावा वर्ग है:अजीब व्यवहार जब एक आंतरिक स्थिर जावा वर्ग को संदर्भित

package com.test; 
public class Outer { 
    public static class Inner { public static final String VAL = "Inner"; } 
} 

मैं संदर्भित कर सकते हैं स्केला कोड से VAL निरंतर बस के रूप में आप उम्मीद करेंगे लेकिन कोड संकलन जब मैं कोशिश जो स्केल टूलबॉक्स कंपाइलर का उपयोग करके इस क्षेत्र का संदर्भ देता है, यह विफल रहता है। (स्टैकट्रैक नीचे दिए गए उदाहरण का पालन करता है)।

इस कोड का प्रदर्शन किया है कि मैं क्या मतलब है:

Exception in thread "main" scala.tools.reflect.ToolBoxError: reflective compilation has failed: 

value Inner is not a member of object com.test.Outer 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:319) 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:252) 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:416) 
    at Issue$delayedInit$body.apply(Issue.scala:8) 
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40) 
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 
    at scala.App$$anonfun$main$1.apply(App.scala:71) 
    at scala.App$$anonfun$main$1.apply(App.scala:71) 
    at scala.collection.immutable.List.foreach(List.scala:318) 
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32) 
    at scala.App$class.main(App.scala:71) 
    at Issue$.main(Issue.scala:3) 
    at Issue.main(Issue.scala) 

किसी को भी इस से पहले का सामना करना पड़ा है:

import scala.reflect.runtime.universe 
import scala.tools.reflect.ToolBox 
object Issue extends App { 
    val mirror = universe.runtimeMirror(getClass.getClassLoader) 
    val toolbox = ToolBox(mirror).mkToolBox() 
    println     (com.test.Outer.Inner.VAL) // prints 'Inner' 
    val tree = toolbox.parse("com.test.Outer.Inner.VAL") 
    val compiled = toolbox.compile(tree)() // fails to compile 
} 

यह अपवाद ट्रेस मैं मिलता है? क्या यह काम करने के लिए मैं कुछ भी बदल सकता हूं (यानी कंपाइलर विकल्प)?

धन्यवाद।

संपादित

यह जब मैं के साथ "-verbose -Yissue-डिबग" संकलन मैं क्या मिलता है: मुझे लगता है यह एक बग है

[reflect-compiler] made Scala package scala 
[reflect-compiler] unpickling Scala package package and package scala, owner = package scala 
[reflect-compiler] made Scala package java 
[reflect-compiler] made Scala package lang 
[reflect-compiler] made Scala package runtime 
[reflect-compiler] made Scala package annotation 
[reflect-compiler] unpickling Scala package package and package runtime, owner = package runtime 
[reflect-compiler] made Scala package collection 
[reflect-compiler] unpickling Scala package package and package collection, owner = package collection 
[reflect-compiler] translating reflection info for Java class java.lang.Object 
[reflect-compiler] unpickling Scala class Unit and object Unit, owner = package scala 
[reflect-compiler] translating reflection info for Java class java.lang.Throwable 
[reflect-compiler] unpickling Scala class Long and object Long, owner = package scala 
[reflect-compiler] translating reflection info for Java class java.lang.InterruptedException 
[reflect-compiler] unpickling Scala class Int and object Int, owner = package scala 
[reflect-compiler] unpickling Scala class Boolean and object Boolean, owner = package scala 
[reflect-compiler] translating reflection info for Java class java.lang.String 
[reflect-compiler] translating reflection info for Java class java.lang.CloneNotSupportedException 
[reflect-compiler] made Scala package io 
[reflect-compiler] translating reflection info for Java interface java.io.Serializable 
[reflect-compiler] translating reflection info for Java interface java.lang.CharSequence 
[reflect-compiler] unpickling Scala class Char and object Char, owner = package scala 
[reflect-compiler] translating reflection info for Java class java.io.ObjectStreamField 
[reflect-compiler] made Scala package util 
[reflect-compiler] unpickling Scala class Float and object Float, owner = package scala 
[reflect-compiler] unpickling Scala class Double and object Double, owner = package scala 
[reflect-compiler] unpickling Scala class Byte and object Byte, owner = package scala 
[reflect-compiler] translating reflection info for Java class java.lang.StringBuffer 
[reflect-compiler] translating reflection info for Java class java.util.Locale 
[reflect-compiler] translating reflection info for Java class java.io.UnsupportedEncodingException 
[reflect-compiler] made Scala package nio 
[reflect-compiler] made Scala package charset 
[reflect-compiler] translating reflection info for Java class java.nio.charset.Charset 
[reflect-compiler] translating reflection info for Java class java.lang.StringBuilder 
[reflect-compiler] translating reflection info for Java interface java.lang.Comparable 
[reflect-compiler] made Scala package beans 
parsing com.test.Outer.Inner.VAL 
importing com.test.Outer.Inner.VAL 
compiling com.test.Outer.Inner.VAL 
[reflect-compiler] unpickling Scala class Predef and object Predef, owner = package scala 
[reflect-compiler] unpickling Scala class ClassfileAnnotation and object ClassfileAnnotation, owner = package annotation 
[reflect-compiler] unpickling Scala class Annotation and object Annotation, owner = package annotation 
[reflect-compiler] unpickling Scala class StaticAnnotation and object StaticAnnotation, owner = package annotation 
[reflect-compiler] made Scala package reflect 
[reflect-compiler] unpickling Scala package package and package reflect, owner = package reflect 
[reflect-compiler] made Scala package api 
[reflect-compiler] unpickling Scala package package and package api, owner = package api 
[reflect-compiler] unpickling Scala class Universe and object Universe, owner = package api 
[reflect-compiler] unpickling Scala class Symbols and object Symbols, owner = package api 
[reflect-compiler] unpickling Scala class Types and object Types, owner = package api 
[reflect-compiler] unpickling Scala class FlagSets and object FlagSets, owner = package api 
[reflect-compiler] unpickling Scala class Scopes and object Scopes, owner = package api 
[reflect-compiler] unpickling Scala class Names and object Names, owner = package api 
[reflect-compiler] unpickling Scala class Trees and object Trees, owner = package api 
[reflect-compiler] unpickling Scala class Constants and object Constants, owner = package api 
[reflect-compiler] unpickling Scala class Annotations and object Annotations, owner = package api 
[reflect-compiler] unpickling Scala class Positions and object Positions, owner = package api 
[reflect-compiler] unpickling Scala class Exprs and object Exprs, owner = package api 
[reflect-compiler] unpickling Scala class TypeTags and object TypeTags, owner = package api 
[reflect-compiler] unpickling Scala class TagInterop and object TagInterop, owner = package api 
[reflect-compiler] unpickling Scala class StandardDefinitions and object StandardDefinitions, owner = package api 
[reflect-compiler] unpickling Scala class StandardNames and object StandardNames, owner = package api 
[reflect-compiler] unpickling Scala class BuildUtils and object BuildUtils, owner = package api 
[reflect-compiler] unpickling Scala class Mirrors and object Mirrors, owner = package api 
[reflect-compiler] unpickling Scala class Printers and object Printers, owner = package api 
[reflect-compiler] unpickling Scala class Importers and object Importers, owner = package api 
[reflect-compiler] made Scala package runtime 
[reflect-compiler] unpickling Scala package package and package runtime, owner = package runtime 
[reflect-compiler] unpickling Scala class StringContext and object StringContext, owner = package scala 
[reflect-compiler] unpickling Scala class Product and object Product, owner = package scala 
[reflect-compiler] unpickling Scala class Equals and object Equals, owner = package scala 
[reflect-compiler] unpickling Scala class Serializable and object Serializable, owner = package scala 
[reflect-compiler] made Scala package immutable 
[reflect-compiler] unpickling Scala package package and package immutable, owner = package immutable 
[reflect-compiler] unpickling Scala class Array and object Array, owner = package scala 
[reflect-compiler] translating reflection info for Java interface java.lang.Cloneable 
[reflect-compiler] unpickling Scala class AnyVal and object AnyVal, owner = package scala 
[reflect-compiler] unpickling Scala class NotNull and object NotNull, owner = package scala 
[reflect-compiler] unpickling Scala class LowPriorityImplicits and object LowPriorityImplicits, owner = package scala 
[reflect-compiler] made Scala package com 
[reflect-compiler] unpickling Scala class Dynamic and object Dynamic, owner = package scala 
[reflect-compiler] made Scala package test 
[reflect-compiler] translating reflection info for Java class com.test.Outer 
[reflect-compiler] *** missing: Inner/true/object Outer/false/class scala.reflect.runtime.SynchronizedOps$$anon$1 
java.lang.Exception 
    at scala.tools.nsc.typechecker.Contexts$Context.issue(Contexts.scala:399) 
    at scala.tools.nsc.typechecker.ContextErrors$ErrorUtils$.issueTypeError(ContextErrors.scala:84) 
    at scala.tools.nsc.typechecker.ContextErrors$ErrorUtils$.issueNormalTypeError(ContextErrors.scala:69) 
    at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.NotAMemberError(ContextErrors.scala:331) 
    at scala.tools.nsc.typechecker.Typers$Typer.handleMissing$1(Typers.scala:4846) 
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedSelect$1(Typers.scala:4851) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:4938) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5551) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5710) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5716) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:4918) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5551) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630) 
    at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.scala:5825) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:2250) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5557) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630) 
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2921) 
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025) 
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025) 
    at scala.collection.immutable.List.loop$1(List.scala:170) 
    at scala.collection.immutable.List.mapConserve(List.scala:186) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3025) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1914) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1794) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5572) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630) 
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2921) 
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025) 
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3025) 
    at scala.collection.immutable.List.loop$1(List.scala:170) 
    at scala.collection.immutable.List.mapConserve(List.scala:186) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3025) 
    at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5288) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5575) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5630) 
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5687) 
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99) 
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463) 
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91) 
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91) 
    at scala.collection.Iterator$class.foreach(Iterator.scala:727) 
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157) 
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:91) 
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582) 
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556) 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:251) 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:416) 
    at Issue$delayedInit$body.apply(Issue.scala:8) 
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40) 
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 
    at scala.App$$anonfun$main$1.apply(App.scala:71) 
    at scala.App$$anonfun$main$1.apply(App.scala:71) 
    at scala.collection.immutable.List.foreach(List.scala:318) 
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32) 
    at scala.App$class.main(App.scala:71) 
    at Issue$.main(Issue.scala:3) 
    at Issue.main(Issue.scala) 
Exception in thread "main" scala.tools.reflect.ToolBoxError: reflective compilation has failed: 

[namer in 31ms] 
[packageobjects in 0ms] 
value Inner is not a member of object com.test.Outer 
[typer in 211ms] 
[total in 247ms] 
[reset] recursing in package <root> 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:319) 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:252) 
    at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:416) 
    at Issue$delayedInit$body.apply(Issue.scala:8) 
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40) 
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 
    at scala.App$$anonfun$main$1.apply(App.scala:71) 
    at scala.App$$anonfun$main$1.apply(App.scala:71) 
    at scala.collection.immutable.List.foreach(List.scala:318) 
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32) 
    at scala.App$class.main(App.scala:71) 
    at Issue$.main(Issue.scala:3) 
    at Issue.main(Issue.scala) 

संपादित 2

प्रतिबिंब एपीआई में लेकिन मुझे यकीन नहीं है। मैं टाइपिंग चरण डिबग है और निम्नलिखित के साथ आए हैं:

com.test.Outer के बाद एक उपयुक्त प्रतीक के साथ सौंपा गया है, हम com.test.Outer.Inner की टाइपिंग चरण तक पहुँचते हैं।

वहां scala.reflect.internal.Scopes.Scope#lookupEntry(Name) का उपयोग करके यह एक प्रतीक दिखता है।

निरीक्षण देखा पर गुंजाइश का पता चलता है कि यह Inner के ClassSymbol लेकिन गुंजाइश प्रतीक नाम और तरीकों name पैरामीटर किया जाता है के बीच समानता परीक्षण Object#equals (यानी equals ओवरराइड नहीं किया गया है), का उपयोग कर और के लिए एक ScopeEntry में क्या है दो नाम उदाहरण समान नहीं हैं।

प्रतीक के नाम और पारित नाम पैरामीटर के बारे में एक अंतिम नोट यह है कि मुझे लगता है कि उनके पास index फ़ील्ड है। मुझे यकीन नहीं है कि इसका क्या अर्थ है, लेकिन मुझे इंप्रेशन मिला है इसका मतलब है कि वे नाम तालिका में एक ही नाम का उल्लेख करते हैं, इसलिए वे बराबर (?) (दोनों के बीच एक अंतर है, एक TermName है और प्रतीक का नाम TypeName है)।

वैसे भी, मैं शायद एक बग स्काला के बग ट्रैकर खोलूंगा, बस यहां चीजों को समाप्त करना चाहता था।

+0

'toolbox.parse (" com.test.Outer # Inner.VAL ") आज़माएं। – Impredicative

+0

हां, कृपया, एक बग सबमिट करें, और मैं एक नज़र डालेगा। विस्तृत विश्लेषण के लिए धन्यवाद! –

+0

@EugeneBurmako धन्यवाद, हाल ही में खोले एसआई-7378 – dankilman

उत्तर

0

सही - ऐसा लगता है कि स्कैला/जेवीएम प्रतिबिंब एपीआई यह निर्धारित करने में सक्षम नहीं है कि वीएआर नेस्टेड इनर क्लास का एक स्थिर सदस्य है।

संबंधित मुद्दे