Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Add @implicitAmbiguous annotation #26

Closed
puffnfresh opened this issue Sep 6, 2014 · 4 comments
Closed

Add @implicitAmbiguous annotation #26

puffnfresh opened this issue Sep 6, 2014 · 4 comments

Comments

@puffnfresh
Copy link

https://issues.scala-lang.org/browse/SI-6806

Should be pretty straightforward.

Motivation:

trait =!=[A, B]

implicit def neq[A, B] : A =!= B = null

@implicitAmbiguous("Type is required to not equal ${A}")
implicit def neqAmbig1[A] : A =!= A = null
implicit def neqAmbig2[A] : A =!= A = null
@puffnfresh puffnfresh self-assigned this Sep 6, 2014
@propensive
Copy link

We should consider how this might interact with #25.

As I see it, it ought to be fine -- it's just the "other reason" why implicit search may fail, and the @implicitAmbiguous error messages should be shown in the list too.

Tell me if I'm oversimplifying this.

@milessabin
Copy link
Member

👍

@puffnfresh
Copy link
Author

We should be able to give a nice error for any2stringadd but currently the annotation is not used in the right spot. That should be an easy fix.

@puffnfresh puffnfresh removed their assignment Dec 13, 2014
puffnfresh pushed a commit to puffnfresh/scala that referenced this issue Jul 30, 2015
In Scala 2.8.2, an optimization was added to create a static
cache for Symbol literals (ie, the results of `Symbol.apply("foo"))`.
This saves the map lookup on the second pass through code.

This actually was broken somewhere during the Scala 2.10 series,
after the addition of an overloaded `apply` method to `Symbol`.

The cache synthesis code was made aware of the overload and brought
back to working condition recently, in scala#3149.

However, this has uncovered a latent bug when the Symbol literals are
defined with traits.

One of the enclosed tests failed with:

	  jvm > t8933b-run.log
	java.lang.IllegalAccessError: tried to access field MotherClass.symbol$1 from class MixinWithSymbol$class
	        at MixinWithSymbol$class.symbolFromTrait(A.scala:3)
	        at MotherClass.symbolFromTrait(Test.scala:1)

This commit simply disables the optimization if we are in a trait.
Alternative fixes might be: a) make the static Symbol cache field
public / b) "mixin" the static symbol cache. Neither of these
seem worth the effort and risk for an already fairly situational
optimization.

Here's how the optimization looks in a class:

	% cat sandbox/test.scala; qscalac sandbox/test.scala && echo ":javap C" | qscala;
	class C {
	  'a; 'b
	}
	Welcome to Scala version 2.11.5-20141106-145558-aa558dce6d (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20).
	Type in expressions to have them evaluated.
	Type :help for more information.

	scala> :javap C
	  Size 722 bytes
	  MD5 checksum 6bb00189166917254e8d40499ee7c887
	  Compiled from "test.scala"
	public class C

	{
	  public static {};
	    descriptor: ()V
	    flags: ACC_PUBLIC, ACC_STATIC
	    Code:
	      stack=2, locals=0, args_size=0
	         0: getstatic     typelevel#16                 // Field scala/Symbol$.MODULE$:Lscala/Symbol$;
	         3: ldc           typelevel#18                 // String a
	         5: invokevirtual typelevel#22                 // Method scala/Symbol$.apply:(Ljava/lang/String;)Lscala/Symbol;
	         8: putstatic     typelevel#26                 // Field symbol$1:Lscala/Symbol;
	        11: getstatic     typelevel#16                 // Field scala/Symbol$.MODULE$:Lscala/Symbol$;
	        14: ldc           typelevel#28                 // String b
	        16: invokevirtual typelevel#22                 // Method scala/Symbol$.apply:(Ljava/lang/String;)Lscala/Symbol;
	        19: putstatic     typelevel#31                 // Field symbol$2:Lscala/Symbol;
	        22: return

	  public C();
	    descriptor: ()V
	    flags: ACC_PUBLIC
	    Code:
	      stack=1, locals=1, args_size=1
	         0: aload_0
	         1: invokespecial typelevel#34                 // Method java/lang/Object."<init>":()V
	         4: getstatic     typelevel#26                 // Field symbol$1:Lscala/Symbol;
	         7: pop
	         8: getstatic     typelevel#31                 // Field symbol$2:Lscala/Symbol;
	        11: pop
	        12: return
	}

fixup
@SethTisue
Copy link
Member

merged in main repo: scala#4673

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

No branches or pull requests

4 participants