Skip to content

Commit 931f156

Browse files
committed
SPARK-17424: Fix unsound substitution bug in ScalaReflection.
Substitution fails when the actual type args are empty because they are still unknown. Instead, when there are no resolved types to subsitute, return the formal type args with unresovled type parameters.
1 parent 8087ecf commit 931f156

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,16 @@ trait ScalaReflection {
785785
def getConstructorParameters(tpe: Type): Seq[(String, Type)] = {
786786
val formalTypeArgs = tpe.typeSymbol.asClass.typeParams
787787
val TypeRef(_, _, actualTypeArgs) = tpe
788-
constructParams(tpe).map { p =>
789-
p.name.toString -> p.typeSignature.substituteTypes(formalTypeArgs, actualTypeArgs)
788+
val params = constructParams(tpe)
789+
// if there are type variables to fill in, do the substitution (SomeClass[T] -> SomeClass[Int])
790+
if (actualTypeArgs.nonEmpty) {
791+
params.map { p =>
792+
p.name.toString -> p.typeSignature.substituteTypes(formalTypeArgs, actualTypeArgs)
793+
}
794+
} else {
795+
params.map { p =>
796+
p.name.toString -> p.typeSignature
797+
}
790798
}
791799
}
792800

0 commit comments

Comments
 (0)