I need to define a component that derives from another component, both have constructors with arguments (for service injection). However, Component macro expansion fails with these classes, it says that the parent class does not take parameters (whereas it does).
I have prepared a minimal project exposing this behaviour (with an Int constructor parameter for simplicity): https://github.com/linnando/angulate2test The pair AbstractTestComponent and TestComponent does not cause any problems, but AbstractTestWithConstructorComponent and TestWithConstructorComponent fail with the following message:
sbt> fastOptJS
[info] Updating {file:/home/linnando/projects/angulate2test/}root...
[info] Resolving org.eclipse.jetty#jetty-continuation;8.1.16.v20140903 ...
[info] Done updating.
[info] Compiling 5 Scala sources to /home/linnando/projects/angulate2test/target/scala-2.11/classes...
[error] /home/linnando/projects/angulate2test/src/main/scala/quickstart/TestWithConstructorComponent.scala:5: exception during macro expansion:
[error] scala.reflect.macros.TypecheckException: quickstart.AbstractTestWithConstructorComponent does not take parameters
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:34)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23)
[error] at scala.reflect.macros.contexts.Typers$class.withContext$1(Typers.scala:25)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Typers$class.withWrapping$1(Typers.scala:26)
[error] at scala.reflect.macros.contexts.Typers$class.typecheck(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6)
[error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6)
[error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1$$anonfun$apply$1.apply(ClassDecorator.scala:130)
[error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1$$anonfun$apply$1.apply(ClassDecorator.scala:130)
[error] at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
[error] at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
[error] at scala.collection.immutable.List.foreach(List.scala:392)
[error] at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
[error] at scala.collection.immutable.List.map(List.scala:296)
[error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1.apply(ClassDecorator.scala:130)
[error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1.apply(ClassDecorator.scala:121)
[error] at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52)
[error] at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52)
[error] at de.surfice.smacrotools.MacroAnnotationHandler.transformDef(MacroAnnotationHandler.scala:163)
[error] at de.surfice.smacrotools.MacroAnnotationHandler.handleClassDef(MacroAnnotationHandler.scala:54)
[error] at de.surfice.smacrotools.MacroAnnotationHandler.impl(MacroAnnotationHandler.scala:35)
[error] @Component(
[error] ^
[error] /home/linnando/projects/angulate2test/src/main/scala/quickstart/Main.scala:6: exception during macro expansion:
[error] scala.reflect.macros.TypecheckException: Cannot get JS reference for type quickstart.TestWithConstructorComponent
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:34)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23)
[error] at scala.reflect.macros.contexts.Typers$class.withContext$1(Typers.scala:25)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28)
[error] at scala.reflect.internal.Trees$class.wrappingIntoTerm(Trees.scala:1716)
[error] at scala.reflect.internal.SymbolTable.wrappingIntoTerm(SymbolTable.scala:16)
[error] at scala.reflect.macros.contexts.Typers$class.withWrapping$1(Typers.scala:26)
[error] at scala.reflect.macros.contexts.Typers$class.typecheck(Typers.scala:28)
[error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6)
[error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6)
[error] at de.surfice.smacrotools.CommonMacroTools.parseAnnotParams$1(CommonMacroTools.scala:116)
[error] at de.surfice.smacrotools.CommonMacroTools.extractAnnotationParameters(CommonMacroTools.scala:139)
[error] at angulate2.internal.ClassDecorator.mainAnnotationParams(ClassDecorator.scala:145)
[error] at angulate2.internal.ClassDecorator.angulate2$internal$ClassDecorator$$initClassDecoratorData(ClassDecorator.scala:179)
[error] at angulate2.internal.ClassDecorator$$anonfun$analyze$1.apply(ClassDecorator.scala:70)
[error] at angulate2.internal.ClassDecorator$$anonfun$analyze$1.apply(ClassDecorator.scala:68)
[error] at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52)
[error] at de.surfice.smacrotools.MacroAnnotationHandler.de$surfice$smacrotools$MacroAnnotationHandler$$initData(MacroAnnotationHandler.scala:30)
[error] at de.surfice.smacrotools.MacroAnnotationHandler$TransformData$.apply(MacroAnnotationHandler.scala:85)
[error] at de.surfice.smacrotools.MacroAnnotationHandler.handleClassDef(MacroAnnotationHandler.scala:54)
[error] at de.surfice.smacrotools.MacroAnnotationHandler.impl(MacroAnnotationHandler.scala:35)
[error] @NgModule(
[error] ^
[error] /home/linnando/projects/angulate2test/src/main/scala/quickstart/Main.scala:8: Cannot get JS reference for type quickstart.TestWithConstructorComponent
[error] declarations = @@[AppComponent, TestComponent, TestWithConstructorComponent],
[error] ^
[error] three errors found
[error] (compile:compileIncremental) Compilation failed
It seems that AbstractTestWithConstructorComponent type information during macro expansion misses the information about the constructor. Maybe, some extra annotation is required, but I could not find an annotation that would give the desired effect.
I need to define a component that derives from another component, both have constructors with arguments (for service injection). However, Component macro expansion fails with these classes, it says that the parent class does not take parameters (whereas it does).
I have prepared a minimal project exposing this behaviour (with an Int constructor parameter for simplicity): https://github.com/linnando/angulate2test The pair AbstractTestComponent and TestComponent does not cause any problems, but AbstractTestWithConstructorComponent and TestWithConstructorComponent fail with the following message:
sbt> fastOptJS [info] Updating {file:/home/linnando/projects/angulate2test/}root... [info] Resolving org.eclipse.jetty#jetty-continuation;8.1.16.v20140903 ... [info] Done updating. [info] Compiling 5 Scala sources to /home/linnando/projects/angulate2test/target/scala-2.11/classes... [error] /home/linnando/projects/angulate2test/src/main/scala/quickstart/TestWithConstructorComponent.scala:5: exception during macro expansion: [error] scala.reflect.macros.TypecheckException: quickstart.AbstractTestWithConstructorComponent does not take parameters [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:34) [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:28) [error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24) [error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24) [error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25) [error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25) [error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23) [error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23) [error] at scala.reflect.macros.contexts.Typers$class.withContext$1(Typers.scala:25) [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28) [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28) [error] at scala.reflect.macros.contexts.Typers$class.withWrapping$1(Typers.scala:26) [error] at scala.reflect.macros.contexts.Typers$class.typecheck(Typers.scala:28) [error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6) [error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6) [error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1$$anonfun$apply$1.apply(ClassDecorator.scala:130) [error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1$$anonfun$apply$1.apply(ClassDecorator.scala:130) [error] at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) [error] at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) [error] at scala.collection.immutable.List.foreach(List.scala:392) [error] at scala.collection.TraversableLike$class.map(TraversableLike.scala:234) [error] at scala.collection.immutable.List.map(List.scala:296) [error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1.apply(ClassDecorator.scala:130) [error] at angulate2.internal.ClassDecorator$$anonfun$commonTransform$1.apply(ClassDecorator.scala:121) [error] at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52) [error] at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52) [error] at de.surfice.smacrotools.MacroAnnotationHandler.transformDef(MacroAnnotationHandler.scala:163) [error] at de.surfice.smacrotools.MacroAnnotationHandler.handleClassDef(MacroAnnotationHandler.scala:54) [error] at de.surfice.smacrotools.MacroAnnotationHandler.impl(MacroAnnotationHandler.scala:35) [error] @Component( [error] ^ [error] /home/linnando/projects/angulate2test/src/main/scala/quickstart/Main.scala:6: exception during macro expansion: [error] scala.reflect.macros.TypecheckException: Cannot get JS reference for type quickstart.TestWithConstructorComponent [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:34) [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2$$anonfun$apply$1.apply(Typers.scala:28) [error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24) [error] at scala.reflect.macros.contexts.Typers$$anonfun$3.apply(Typers.scala:24) [error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25) [error] at scala.reflect.macros.contexts.Typers$$anonfun$withContext$1$1.apply(Typers.scala:25) [error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23) [error] at scala.reflect.macros.contexts.Typers$$anonfun$1.apply(Typers.scala:23) [error] at scala.reflect.macros.contexts.Typers$class.withContext$1(Typers.scala:25) [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28) [error] at scala.reflect.macros.contexts.Typers$$anonfun$typecheck$2.apply(Typers.scala:28) [error] at scala.reflect.internal.Trees$class.wrappingIntoTerm(Trees.scala:1716) [error] at scala.reflect.internal.SymbolTable.wrappingIntoTerm(SymbolTable.scala:16) [error] at scala.reflect.macros.contexts.Typers$class.withWrapping$1(Typers.scala:26) [error] at scala.reflect.macros.contexts.Typers$class.typecheck(Typers.scala:28) [error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6) [error] at scala.reflect.macros.contexts.Context.typecheck(Context.scala:6) [error] at de.surfice.smacrotools.CommonMacroTools.parseAnnotParams$1(CommonMacroTools.scala:116) [error] at de.surfice.smacrotools.CommonMacroTools.extractAnnotationParameters(CommonMacroTools.scala:139) [error] at angulate2.internal.ClassDecorator.mainAnnotationParams(ClassDecorator.scala:145) [error] at angulate2.internal.ClassDecorator.angulate2$internal$ClassDecorator$$initClassDecoratorData(ClassDecorator.scala:179) [error] at angulate2.internal.ClassDecorator$$anonfun$analyze$1.apply(ClassDecorator.scala:70) [error] at angulate2.internal.ClassDecorator$$anonfun$analyze$1.apply(ClassDecorator.scala:68) [error] at scala.Function1$$anonfun$andThen$1.apply(Function1.scala:52) [error] at de.surfice.smacrotools.MacroAnnotationHandler.de$surfice$smacrotools$MacroAnnotationHandler$$initData(MacroAnnotationHandler.scala:30) [error] at de.surfice.smacrotools.MacroAnnotationHandler$TransformData$.apply(MacroAnnotationHandler.scala:85) [error] at de.surfice.smacrotools.MacroAnnotationHandler.handleClassDef(MacroAnnotationHandler.scala:54) [error] at de.surfice.smacrotools.MacroAnnotationHandler.impl(MacroAnnotationHandler.scala:35) [error] @NgModule( [error] ^ [error] /home/linnando/projects/angulate2test/src/main/scala/quickstart/Main.scala:8: Cannot get JS reference for type quickstart.TestWithConstructorComponent [error] declarations = @@[AppComponent, TestComponent, TestWithConstructorComponent], [error] ^ [error] three errors found [error] (compile:compileIncremental) Compilation failed
It seems that AbstractTestWithConstructorComponent type information during macro expansion misses the information about the constructor. Maybe, some extra annotation is required, but I could not find an annotation that would give the desired effect.