File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -374,6 +374,9 @@ extension TokenConsumer {
374374 return false
375375 }
376376
377+ case . prefixOperator where lexeme. isContextualPunctuator ( " ~ " ) :
378+ return true
379+
377380 default :
378381 return false
379382 }
Original file line number Diff line number Diff line change @@ -343,6 +343,75 @@ final class TypeTests: ParserTestCase {
343343 )
344344 }
345345
346+ func testInverseTypesAsExpr( ) {
347+ assertParse (
348+ " (~Copyable).self "
349+ )
350+
351+ assertParse (
352+ " ~Copyable.self "
353+ )
354+
355+ assertParse (
356+ " (any ~Copyable).self "
357+ )
358+ }
359+
360+ func testInverseTypesInParameter( ) {
361+ assertParse (
362+ " func f(_: borrowing ~Copyable) {} "
363+ )
364+
365+ assertParse (
366+ " func f(_: consuming ~Copyable) {} "
367+ )
368+
369+ assertParse (
370+ " func f(_: borrowing any ~Copyable) {} "
371+ )
372+
373+ assertParse (
374+ " func f(_: consuming any ~Copyable) {} "
375+ )
376+
377+ assertParse (
378+ " func f(_: ~Copyable) {} "
379+ )
380+
381+ assertParse (
382+ " typealias T = (~Copyable) -> Void "
383+ )
384+
385+ assertParse (
386+ " typealias T = (_ x: ~Copyable) -> Void "
387+ )
388+
389+ assertParse (
390+ " typealias T = (borrowing ~Copyable) -> Void "
391+ )
392+
393+ assertParse (
394+ " typealias T = (_ x: borrowing ~Copyable) -> Void "
395+ )
396+
397+ assertParse (
398+ " typealias T = (borrowing any ~Copyable) -> Void "
399+ )
400+
401+ assertParse (
402+ " typealias T = (_ x: borrowing any ~Copyable) -> Void "
403+ )
404+
405+ assertParse (
406+ " func f(_: any borrowing 1️⃣~Copyable) {} " ,
407+ diagnostics: [
408+ DiagnosticSpec (
409+ message: " unexpected code '~Copyable' in parameter clause "
410+ )
411+ ]
412+ )
413+ }
414+
346415 func testTypedThrows( ) {
347416 assertParse (
348417 """
You can’t perform that action at this time.
0 commit comments