@@ -308,40 +308,140 @@ class CompletionTest {
308308
309309 @ Test def completeExtensionMethodWithTypeParameter : Unit = {
310310 code """ object Foo
311- |extension [A] (foo: Foo.type) def xxxx: Int = 1
311+ |extension (foo: Foo.type) def xxxx[A] : Int = 1
312312 |object Main { Foo.xx ${m1} } """ .withSource
313313 .completion(m1, Set ((" xxxx" , Method , " [A] => Int" )))
314314 }
315315
316316 @ Test def completeExtensionMethodWithParameterAndTypeParameter : Unit = {
317317 code """ object Foo
318- |extension [A] (foo: Foo.type) def xxxx(a: A) = a
318+ |extension (foo: Foo.type) def xxxx[A] (a: A) = a
319319 |object Main { Foo.xx ${m1} } """ .withSource
320320 .completion(m1, Set ((" xxxx" , Method , " [A](a: A): A" )))
321321 }
322322
323- @ Test def completeExtensionMethodFromExtenionWithAUsingSection : Unit = {
323+ @ Test def completeExtensionMethodFromExtensionWithTypeParameter : Unit = {
324+ code """ extension [A](a: A) def xxxx: A = a
325+ |object Main { "abc".xx ${m1} } """ .withSource
326+ .completion(m1, Set ((" xxxx" , Method , " => String" )))
327+ }
328+
329+ @ Test def completeExtensionMethodWithResultTypeDependantOnReceiver : Unit = {
330+ code """ trait Foo { type Out; def get: Out}
331+ |object Bar extends Foo { type Out = String; def get: Out = "abc"}
332+ |extension (foo: Foo) def xxxx: foo.Out = foo.get
333+ |object Main { Bar.xx ${m1} } """ .withSource
334+ .completion(m1, Set ((" xxxx" , Method , " => String" )))
335+ }
336+
337+ @ Test def completeExtensionMethodFromExtenionWithPrefixUsingSection : Unit = {
324338 code """ object Foo
325339 |trait Bar
326340 |trait Baz
327- |given Bar = new Bar {}
328- |given Baz = new Baz {}
341+ |given Bar with {}
342+ |given Baz with {}
343+ |extension (using Bar, Baz)(foo: Foo.type) def xxxx = 1
344+ |object Main { Foo.xx ${m1} } """ .withSource
345+ .completion(m1, Set ((" xxxx" , Method , " => Int" )))
346+ }
347+
348+ @ Test def completeExtensionMethodFromExtenionWithMultiplePrefixUsingSections : Unit = {
349+ code """ object Foo
350+ |trait Bar
351+ |trait Baz
352+ |given Bar with {}
353+ |given Baz with {}
354+ |extension (using Bar)(using Baz)(foo: Foo.type) def xxxx = 1
355+ |object Main { Foo.xx ${m1} } """ .withSource
356+ .completion(m1, Set ((" xxxx" , Method , " => Int" )))
357+ }
358+
359+ @ Test def dontCompleteExtensionMethodFromExtenionWithMissingImplicitFromPrefixUsingSection : Unit = {
360+ code """ object Foo
361+ |trait Bar
362+ |trait Baz
363+ |given Baz with {}
364+ |extension (using Bar, Baz)(foo: Foo.type) def xxxx = 1
365+ |object Main { Foo.xx ${m1} } """ .withSource
366+ .completion(m1, Set ())
367+ }
368+
369+ @ Test def completeExtensionMethodForReceiverOfTypeDependentOnLeadingImplicits : Unit = {
370+ code """
371+ |trait Foo:
372+ | type Out <: Bar
373+ |
374+ |given Foo with
375+ | type Out = Baz
376+ |
377+ |trait Bar:
378+ | type Out
379+ |
380+ |trait Baz extends Bar
381+ |
382+ |given Baz with
383+ | type Out = Quux
384+ |
385+ |class Quux
386+ |
387+ |object Quux:
388+ | extension (using foo: Foo)(using fooOut: foo.Out)(fooOutOut: fooOut.Out) def xxxx = "abc"
389+ |
390+ |object Main { (new Quux).xx ${m1} } """ .withSource
391+ .completion(m1, Set ((" xxxx" , Method , " => String" )))
392+ }
393+
394+ @ Test def completeExtensionMethodWithResultTypeDependentOnLeadingImplicit : Unit = {
395+ code """ object Foo
396+ |trait Bar { type Out; def get: Out }
397+ |given Bar with { type Out = 123; def get: Out = 123 }
398+ |extension (using bar: Bar)(foo: Foo.type) def xxxx: bar.Out = bar.get
399+ |object Main { Foo.xx ${m1} } """ .withSource
400+ .completion(m1, Set ((" xxxx" , Method , " => (123 : Int)" )))
401+ }
402+
403+ @ Test def completeExtensionMethodFromExtenionWithPostfixUsingSection : Unit = {
404+ code """ object Foo
405+ |trait Bar
406+ |trait Baz
407+ |given Bar with {}
408+ |given Baz with {}
329409 |extension (foo: Foo.type)(using Bar, Baz) def xxxx = 1
330410 |object Main { Foo.xx ${m1} } """ .withSource
331411 .completion(m1, Set ((" xxxx" , Method , " (using x$2: Bar, x$3: Baz): Int" )))
332412 }
333413
334- @ Test def completeExtensionMethodFromExtenionWithMultipleUsingSections : Unit = {
414+ @ Test def completeExtensionMethodFromExtenionWithMultiplePostfixUsingSections : Unit = {
335415 code """ object Foo
336416 |trait Bar
337417 |trait Baz
338- |given Bar = new Bar {}
339- |given Baz = new Baz {}
418+ |given Bar with {}
419+ |given Baz with {}
340420 |extension (foo: Foo.type)(using Bar)(using Baz) def xxxx = 1
341421 |object Main { Foo.xx ${m1} } """ .withSource
342422 .completion(m1, Set ((" xxxx" , Method , " (using x$2: Bar)(using x$3: Baz): Int" )))
343423 }
344424
425+ @ Test def completeExtensionMethodWithTypeParameterFromExtenionWithTypeParametersAndPrefixAndPostfixUsingSections : Unit = {
426+ code """ trait Bar
427+ |trait Baz
428+ |given Bar with {}
429+ |given Baz with {}
430+ |extension [A](using bar: Bar)(a: A)(using baz: Baz) def xxxx[B]: Either[A, B] = Left(a)
431+ |object Main { 123.xx ${m1} } """ .withSource
432+ .completion(m1, Set ((" xxxx" , Method , " (using baz: Baz): [B] => Either[Int, B]" )))
433+ }
434+
435+ @ Test def completeExtensionMethodWithTypeBounds : Unit = {
436+ code """ trait Foo
437+ |trait Bar extends Foo
438+ |given Bar with {}
439+ |extension [A >: Bar](a: A) def xxxx[B <: a.type]: Either[A, B] = Left(a)
440+ |val foo = new Foo {}
441+ |object Main { foo.xx ${m1} } """ .withSource
442+ .completion(m1, Set ((" xxxx" , Method , " [B <: (foo : Foo)] => Either[Foo, B]" )))
443+ }
444+
345445 @ Test def completeInheritedExtensionMethod : Unit = {
346446 code """ object Foo
347447 |trait FooOps {
@@ -442,10 +542,9 @@ class CompletionTest {
442542 .completion(m1, Set ((" xxxx" , Method , " => Int" )))
443543 }
444544
445- @ Test def dontCompleteInapplicableExtensionMethod : Unit = {
446- code """ case class Foo[A](a: A)
447- |extension (foo: Foo[Int]) def xxxx = foo.a
448- |object Main { Foo("abc").xx ${m1} } """ .withSource
545+ @ Test def dontCompleteExtensionMethodWithMismatchedReceiverType : Unit = {
546+ code """ extension (i: Int) def xxxx = i
547+ |object Main { "abc".xx ${m1} } """ .withSource
449548 .completion(m1, Set ())
450549 }
451550}
0 commit comments