@@ -83,12 +83,12 @@ class Interpreter(implicit ctx: Context) {
83
83
val paramClasses = paramsSig(fn.symbol)
84
84
val interpretedArgs = args.map(arg => interpretTreeImpl(arg, env))
85
85
val constructor = getConstructor(clazz, paramClasses)
86
- interpreted (constructor.newInstance(interpretedArgs : _* ))
86
+ stopIfRuntimeException (constructor.newInstance(interpretedArgs : _* ))
87
87
88
88
case _ : RefTree if tree.symbol.isStatic =>
89
89
val clazz = loadClass(tree.symbol.owner.companionModule.fullName)
90
90
val method = getMethod(clazz, tree.symbol.name, Nil )
91
- interpreted (method.invoke(null ))
91
+ stopIfRuntimeException (method.invoke(null ))
92
92
93
93
case tree : Apply =>
94
94
val evaluatedPrefix = if (tree.symbol.isStatic) null else interpretPrefix(tree, env)
@@ -98,7 +98,7 @@ class Interpreter(implicit ctx: Context) {
98
98
val paramClasses = paramsSig(tree.symbol)
99
99
val interpretedArgs = interpretArgs(tree, env)
100
100
val method = getMethod(clazz, tree.symbol.name, paramClasses)
101
- interpreted (method.invoke(evaluatedPrefix, interpretedArgs : _* ))
101
+ stopIfRuntimeException (method.invoke(evaluatedPrefix, interpretedArgs : _* ))
102
102
103
103
case tree : Ident if env.contains(tree.symbol) =>
104
104
env(tree.symbol)
@@ -117,11 +117,15 @@ class Interpreter(implicit ctx: Context) {
117
117
case Typed (expr, _) =>
118
118
interpretTreeImpl(expr, env)
119
119
120
- // Getting the underlying value of a value class. The value class is evaluated as its boxed representation
121
- // as values in the interpreter are `Object`s. Therefore we just get it from the enviroment as is.
122
- case Select (qualifier, _)
120
+ case Select (qualifier, name)
123
121
if tree.symbol.owner.isValueClass && tree.symbol.is(ParamAccessor ) && env.contains(qualifier.symbol) =>
124
- env(qualifier.symbol)
122
+ val value = env(qualifier.symbol)
123
+ val clazz = value.getClass
124
+ if (clazz.getCanonicalName != tree.symbol.owner.showFullName) value // Already unboxed
125
+ else {
126
+ val method = getMethod(clazz, name, Nil )
127
+ stopIfRuntimeException(method.invoke(value))
128
+ }
125
129
126
130
case SeqLiteral (elems, _) =>
127
131
elems.map(elem => interpretTreeImpl(elem, env))
@@ -189,7 +193,7 @@ class Interpreter(implicit ctx: Context) {
189
193
}
190
194
}
191
195
192
- private def interpreted [T ](thunk : => T )(implicit pos : Position ): T = {
196
+ private def stopIfRuntimeException [T ](thunk : => T )(implicit pos : Position ): T = {
193
197
try thunk
194
198
catch {
195
199
case ex : RuntimeException =>
0 commit comments