Skip to content

Commit

Permalink
Merge pull request #338 from scala-native/topic/fix-337
Browse files Browse the repository at this point in the history
Fix #337
  • Loading branch information
densh committed Oct 18, 2016
2 parents c857f6a + 14b7caf commit 17b1afe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ abstract class NirCodeGen
else Seq()
})

def genMethodSigParams(sym: Symbol, params: Seq[Symbol]): Seq[nir.Type] = {
def genMethodSigParams(sym: Symbol): Seq[nir.Type] = {
val wereRepeated = exitingPhase(currentRun.typerPhase) {
for {
params <- sym.tpe.paramss
Expand All @@ -356,7 +356,7 @@ abstract class NirCodeGen
}
}.toMap

params.map {
sym.tpe.params.map {
case p
if wereRepeated.getOrElse(p.name, false) &&
isExternModule(sym.owner) =>
Expand All @@ -368,30 +368,21 @@ abstract class NirCodeGen
}

def genMethodSig(
sym: Symbol, forceStatic: Boolean = false): nir.Type.Function =
sym match {
case sym: ModuleSymbol =>
val MethodType(params, res) = sym.tpe

val paramtys = genMethodSigParams(sym, params)
val selfty = genType(sym.owner.tpe)
val retty = genType(res, retty = true)

Type.Function(Seq(Arg(selfty)), retty)

case sym: MethodSymbol =>
val params = sym.paramLists.flatten
val paramtys = genMethodSigParams(sym, params)
val owner = sym.owner
val selfty =
if (forceStatic || isExternModule(owner) || owner.isImplClass) None
else Some(genType(owner.tpe))
val retty =
if (sym.isClassConstructor) Type.Unit
else genType(sym.tpe.resultType, retty = true)

Type.Function((selfty ++: paramtys).map(Arg(_)), retty)
}
sym: Symbol, forceStatic: Boolean = false): nir.Type.Function = {
require(sym.isMethod)

val tpe = sym.tpe
val owner = sym.owner
val paramtys = genMethodSigParams(sym)
val selfty =
if (forceStatic || isExternModule(owner) || owner.isImplClass) None
else Some(genType(owner.tpe))
val retty =
if (sym.isClassConstructor) Type.Unit
else genType(sym.tpe.resultType, retty = true)

Type.Function((selfty ++: paramtys).map(Arg(_)), retty)
}

def genParams(
owner: Symbol, dd: DefDef, isStatic: Boolean): Seq[Val.Local] = {
Expand Down
9 changes: 9 additions & 0 deletions unit-tests/src/main/scala/scala/scalanative/issues/_337.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scala.scalanative.issues

object _337 extends tests.Suite {
test("github.com/scala-native/scala-native/issues/337") {
case class TestObj(value: Int)
val obj = TestObj(10)
assert(obj.value == 10)
}
}
1 change: 1 addition & 0 deletions unit-tests/src/main/scala/tests/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object Main {
java.lang.FloatSuite,
java.lang.DoubleSuite,
java.util.RandomSuite,
scala.scalanative.issues._337,
scala.scalanative.native.CStringSuite,
scala.scalanative.native.CInteropSuite,
scala.ArrayIntCopySuite,
Expand Down

0 comments on commit 17b1afe

Please sign in to comment.