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

trait T { val f1: F1 = ??? }; javascript { new T { val f1: F1 = ... } } compiles without error #12

Open
mattpap opened this issue Sep 27, 2013 · 1 comment

Comments

@mattpap
Copy link

mattpap commented Sep 27, 2013

I was hoping for a (relatively) type safe and lightweight way of providing options to JavaScript APIs. Suppose we have:

scala> object L { def f(opt: Opt): Int = ???; trait Opt { val a: String = ??? } }
defined module L

Then the following:

scala> javascript { L.f(new L.Opt { val a = "a" }) } asString
$anon
L.Opt{}
res0: String = 
L.f({
  a: "a"
})

scala> javascript { new L.Opt { val a = "a" } } asString
res1: String = 
{
  function $anon() {
    this.a = "a";
  };
  new $anon();
}

compiles and generates proper JavaScript, but it should fail like this:

scala> new L.Opt { val a = "a" }
<console>:13: error: overriding value a in class Opt$class of type String;
 value a needs `override' modifier
              new L.Opt { val a = "a" }

I thought that simple c.typeCheck(...) in jsAnonObjDecl will fix this, but apparently this doesn't work (it still type checks).

@nau
Copy link
Owner

nau commented Sep 30, 2013

That's an interesting one. As @xeno_by explained that's because Scala checks overriding during refchecks phase, which apparently is executed after macro expansion. And as after javascript macro expansion there is no original Scala code which should not compile - the original code compiles.
As a solution it's recommended to keep original Scala code after expansion. I'll implement it a bit later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants