Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schematic.StubSchematic can't be used in Scala.JS #34

Closed
kubukoz opened this issue Jan 9, 2022 · 6 comments · Fixed by #38
Closed

schematic.StubSchematic can't be used in Scala.JS #34

kubukoz opened this issue Jan 9, 2022 · 6 comments · Fixed by #38
Labels
bug Something isn't working

Comments

@kubukoz
Copy link
Member

kubukoz commented Jan 9, 2022

It breaks linking because of extending javatime.StubSchematic:

object CompletionSchematic {
  type Result[A] = List[String]
}

class CompletionSchematic extends smithy4s.StubSchematic[CompletionSchematic.Result] {
  def default[A]: List[String] = Nil
}
[error] Referring to non-existent method schematic.javatime$StubSchematic.$init$()void
[error]   called from constructor playground.CompletionSchematic.<init>()void
[error]   called from private playground.completions$.$anonfun$complete$10(scala.collection.immutable.List,smithy4s.Service,playground.smithyql.Query,playground.smithyql.WithSource$Thing)scala.collection.IterableOnce
[error]   called from private playground.completions$.$anonfun$complete$9(scala.collection.immutable.List,smithy4s.Service,typings.vscode.mod.TextDocument,typings.vscode.mod.Position)scala.collection.immutable.List
[error]   called from playground.completions$.complete(smithy4s.Service)scala.Function2
[error]   called from playground.extension$.activate(typings.vscode.mod.ExtensionContext)void
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   playground.completions$
[error]   playground.extension$
[error] There were linking errors
[error] (vscodeJS / Compile / fastLinkJS) There were linking errors
@kubukoz kubukoz changed the title StubSchematic can't be used in Scala.JS schematic.StubSchematic can't be used in Scala.JS Jan 9, 2022
@Baccata Baccata added the bug Something isn't working label Jan 9, 2022
@lewisjkl
Copy link
Contributor

I was taking a look at this earlier and I think I might be missing something. I created a javascript test with the contents:

package schematic

object JavatimeSpec extends weaver.FunSuite {

  object CompletionSchematic {
    type Result[A] = List[String]
  }

  class CompletionSchematic extends StubSchematic[CompletionSchematic.Result] {

    override def genericStruct[S](
        fields: Vector[Field[CompletionSchematic.Result, S, _]]
    )(const: Vector[Any] => S): CompletionSchematic.Result[S] = ???

    def default[A]: List[String] = Nil
  }

  test("testing") {
    val cs = new CompletionSchematic()
    expect(cs.default == Nil)
  }

}

which seems to work without any compilation issues.

The current js implementation of javatime looks like:

package schematic

object javatime {

  trait Syntax

  type Schematic[F[_]] = Any

  object Schematic {
    trait Mixin[F[_]]
  }

  trait StubSchematic[F[_]] extends Schematic.Mixin[F] {}

}

Anyway, more context here would be appreciated so I can reproduce this on my end

@kubukoz
Copy link
Member Author

kubukoz commented Jan 11, 2022

Does that test run? I can compile all right, but fastLinkJS gives me the same thing as before.

In the meantime, I'll try to minimize this from my project...

@kubukoz
Copy link
Member Author

kubukoz commented Jan 11, 2022

https://github.com/kubukoz/schematic-repro

lazy val root = project
  .in(file("."))
  .enablePlugins(ScalaJSPlugin)
  .settings(
    scalaVersion := "2.13.7",
    scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
    scalaJSUseMainModuleInitializer := true,
  )
  // Option #1 - pulls in core via %%
  .enablePlugins(Smithy4sCodegenPlugin)
  // Option #2
  .settings(
    libraryDependencies ++= Seq(
      "com.disneystreaming.smithy4s" %%% "smithy4s-core" % "0.10.0"
    )
  )

I think I see what's wrong, the codegen plugin is pulling in core via %%. For some reason that isn't a problem for anything else that I've been using...

Anyway, removing the plugin-added dependency and using my own one seems to fix it, but I think this should be fixed in the plugin itself...

@lewisjkl
Copy link
Contributor

Ah good catch, I will update that tomorrow

@kubukoz
Copy link
Member Author

kubukoz commented Jan 11, 2022

I wonder if there's a way to have %%% without forcing the Scala.JS plugin to be added to downstream builds...

@lewisjkl
Copy link
Contributor

Yeah I don't think there is a way to do it. I chatted with @Baccata earlier and it seems like removing the core dependency from the plugin is probably the best path forward.

I guess we could go the route of having a setting that can be overridden to prevent the core dependency from loading, but it seems like that sort of thing would cause more confusion than it would save since anyone using scala JS would have to be magically aware of it. Open to other ideas here though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants