File tree 6 files changed +33
-4
lines changed
test/dotty/tools/dotc/semanticdb
6 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ class ExtractSemanticDB extends Phase:
80
80
|| sym.is(Synthetic )
81
81
|| sym.isSetter
82
82
|| sym.isOldStyleImplicitConversion(forImplicitClassOnly = true )
83
- || sym.owner.isGivenInstanceSummoner
83
+ || sym.isTypeParam && sym. owner.isGivenInstanceClass
84
84
|| excludeDefOrUse(sym)
85
85
86
86
private def excludeDefOrUse (sym : Symbol )(using Context ): Boolean =
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ object Tools:
41
41
document.copy(text = text)
42
42
end loadTextDocument
43
43
44
+ def loadTextDocumentUnsafe (scalaAbsolutePath : Path , semanticdbAbsolutePath : Path ): TextDocument =
45
+ val docs = parseTextDocuments(semanticdbAbsolutePath).documents
46
+ assert(docs.length == 1 )
47
+ docs.head.copy(text = new String (Files .readAllBytes(scalaAbsolutePath), StandardCharsets .UTF_8 ))
48
+
44
49
/** Parses SemanticDB text documents from an absolute path to a `*.semanticdb` file. */
45
50
private def parseTextDocuments (path : Path ): TextDocuments =
46
51
val bytes = Files .readAllBytes(path) // NOTE: a semanticdb file is a TextDocuments message, not TextDocument
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ object SymUtils:
87
87
88
88
def isGenericProduct (using Context ): Boolean = whyNotGenericProduct.isEmpty
89
89
90
- /** Is this the an old style implicit conversion?
90
+ /** Is this an old style implicit conversion?
91
91
* @param directOnly only consider explicitly written methods
92
92
* @param forImplicitClassOnly only consider methods generated from implicit classes
93
93
*/
@@ -100,6 +100,7 @@ object SymUtils:
100
100
case _ =>
101
101
false
102
102
103
+ /** Is this the method that summons a structural given instance? */
103
104
def isGivenInstanceSummoner (using Context ): Boolean =
104
105
def isCodefined (info : Type ): Boolean = info.stripPoly match
105
106
case mt : MethodType =>
@@ -111,6 +112,9 @@ object SymUtils:
111
112
self.isCoDefinedGiven(res.typeSymbol)
112
113
self.isAllOf(Given | Method ) && isCodefined(self.info)
113
114
115
+ def isGivenInstanceClass (using Context ): Boolean =
116
+ self.isClass && self.is(Given )
117
+
114
118
def useCompanionAsMirror (using Context ): Boolean = self.linkedClass.exists && ! self.is(Scala2x )
115
119
116
120
/** Is this a sealed class or trait for which a sum mirror is generated?
Original file line number Diff line number Diff line change @@ -25,6 +25,26 @@ import dotty.tools.dotc.util.SourceFile
25
25
@ main def updateExpect =
26
26
SemanticdbTests ().runExpectTest(updateExpectFiles = true )
27
27
28
+ @ main def metac (root : String , source : String ) =
29
+ val rootSrc = Paths .get(root)
30
+ val sourceSrc = Paths .get(source)
31
+ val semanticFile = FileSystems .getDefault.getPathMatcher(" glob:**.semanticdb" )
32
+ def inputFiles (): List [Path ] =
33
+ val ls = Files .walk(rootSrc.resolve(" META-INF" ).resolve(" semanticdb" ))
34
+ val files =
35
+ try ls.filter(p => semanticFile.matches(p)).collect(Collectors .toList).asScala
36
+ finally ls.close()
37
+ require(files.nonEmpty, s " No semanticdb files! $rootSrc" )
38
+ files.toList
39
+ val metacSb : StringBuilder = StringBuilder (5000 )
40
+ for
41
+ semanticdbPath <- inputFiles().sorted
42
+ do
43
+ val doc = Tools .loadTextDocumentUnsafe(sourceSrc.toAbsolutePath, semanticdbPath)
44
+ Tools .metac(doc, Paths .get(doc.uri))(using metacSb)
45
+ Files .write(rootSrc.resolve(" metac.expect" ), metacSb.toString.getBytes(StandardCharsets .UTF_8 ))
46
+
47
+
28
48
@ Category (Array (classOf [BootstrappedOnlyTests ]))
29
49
class SemanticdbTests :
30
50
val javaFile = FileSystems .getDefault.getPathMatcher(" glob:**.java" )
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ given X/*->givens::X#*/ with
25
25
given (using X /* ->givens::X#*/ ): Y /* ->givens::Y#*/ with
26
26
def doY /* <-givens::InventedNames$package.given_Y#doY().*/ = " 7"
27
27
28
- given [T /* <-givens::InventedNames$package.given_Z_T# [T]*/ ]: Z /* ->givens::Z#*/ [T /* ->givens::InventedNames$package.given_Z_T#[T]*/ ] with
28
+ given [T /* <-givens::InventedNames$package.given_Z_T(). [T]*/ ]: Z /* ->givens::Z#*/ [T /* ->givens::InventedNames$package.given_Z_T#[T]*/ ] with
29
29
def doZ /* <-givens::InventedNames$package.given_Z_T#doZ().*/ : List /* ->scala::package.List#*/ [T /* ->givens::InventedNames$package.given_Z_T#[T]*/ ] = Nil /* ->scala::package.Nil.*/
30
30
31
31
Original file line number Diff line number Diff line change @@ -1766,7 +1766,7 @@ Occurrences:
1766
1766
[24:13..24:14): X -> givens/X#
1767
1767
[24:17..24:18): Y -> givens/Y#
1768
1768
[25:6..25:9): doY <- givens/InventedNames$package.given_Y#doY().
1769
- [27:7..27:8): T <- givens/InventedNames$package.given_Z_T# [T]
1769
+ [27:7..27:8): T <- givens/InventedNames$package.given_Z_T(). [T]
1770
1770
[27:11..27:12): Z -> givens/Z#
1771
1771
[27:13..27:14): T -> givens/InventedNames$package.given_Z_T#[T]
1772
1772
[28:6..28:9): doZ <- givens/InventedNames$package.given_Z_T#doZ().
You can’t perform that action at this time.
0 commit comments