@@ -425,3 +425,58 @@ func testLocalVarsFromDeclarationMacros() {
425
425
struct TakesVariadic {
426
426
#emptyDecl( " foo " , " bar " )
427
427
}
428
+
429
+ // Funkiness with static functions introduced via macro expansions.
430
+ @freestanding( declaration, names: named ( foo ( ) ) ) public macro staticFooFunc( ) = #externalMacro( module: " MacroDefinition " , type: " StaticFooFuncMacro " )
431
+ @freestanding ( declaration, names: arbitrary) public macro staticFooFuncArbitrary( ) = #externalMacro( module: " MacroDefinition " , type: " StaticFooFuncMacro " )
432
+
433
+ class HasAnExpandedStatic {
434
+ #staticFooFunc( )
435
+ }
436
+
437
+ class HasAnExpandedStatic2 {
438
+ #staticFooFuncArbitrary( )
439
+ }
440
+
441
+ func testHasAnExpandedStatic( ) {
442
+ #if TEST_DIAGNOSTICS
443
+ foo ( ) // expected-error{{cannot find 'foo' in scope}}
444
+ #endif
445
+ }
446
+
447
+ @freestanding( declaration, names: named ( == ) ) public macro addSelfEqualsOperator( ) = #externalMacro( module: " MacroDefinition " , type: " SelfAlwaysEqualOperator " )
448
+ @freestanding ( declaration, names: arbitrary) public macro addSelfEqualsOperatorArbitrary( ) = #externalMacro( module: " MacroDefinition " , type: " SelfAlwaysEqualOperator " )
449
+ @attached ( member, names: named ( == ) ) public macro AddSelfEqualsMemberOperator( ) = #externalMacro( module: " MacroDefinition " , type: " SelfAlwaysEqualOperator " )
450
+ @attached ( member, names: arbitrary) public macro AddSelfEqualsMemberOperatorArbitrary( ) = #externalMacro( module: " MacroDefinition " , type: " SelfAlwaysEqualOperator " )
451
+
452
+ struct HasEqualsSelf {
453
+ #addSelfEqualsOperator
454
+ }
455
+
456
+ struct HasEqualsSelf2 {
457
+ #addSelfEqualsOperatorArbitrary
458
+ }
459
+
460
+ @AddSelfEqualsMemberOperator
461
+ struct HasEqualsSelf3 {
462
+ }
463
+
464
+ @AddSelfEqualsMemberOperatorArbitrary
465
+ struct HasEqualsSelf4 {
466
+ }
467
+
468
+ func testHasEqualsSelf(
469
+ x: HasEqualsSelf, y: HasEqualsSelf2, z: HasEqualsSelf3, w: HasEqualsSelf4
470
+ ) {
471
+ _ = ( x == true )
472
+ _ = ( y == true )
473
+ #if TEST_DIAGNOSTICS
474
+ // FIXME: This is technically a bug, because we should be able to find the
475
+ // == operator introduced through a member operator. However, we might
476
+ // want to change the rule rather than implement this.
477
+ _ = ( z == true ) // expected-error{{binary operator '==' cannot be applied to operands}}
478
+ // expected-note@-1{{overloads for '==' exist with these partially matching parameter lists}}
479
+ _ = ( w == true ) // expected-error{{binary operator '==' cannot be applied to operands}}
480
+ // expected-note@-1{{overloads for '==' exist with these partially matching parameter lists}}
481
+ #endif
482
+ }
0 commit comments