- Notifications
You must be signed in to change notification settings - Fork 1.1k
Support MatchType for SemanticDB #14608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
7817912 0480dec fa4cb01 28d59a0 2ca6fb2 4fa62e2 2693983 18b8901 b070667 60c336e be31d56 9375ab1 50a43b9 8465366 ba24fe1 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -15,6 +15,7 @@ import collection.mutable | |
| | ||
| import dotty.tools.dotc.{semanticdb => s} | ||
| import Scala3.{FakeSymbol, SemanticSymbol, WildcardTypeSymbol, TypeParamRefSymbol, TermParamRefSymbol, RefinementSymbol} | ||
| import dotty.tools.dotc.core.Names.Designator | ||
| | ||
| class TypeOps: | ||
| import SymbolScopeOps._ | ||
| | @@ -81,6 +82,10 @@ class TypeOps: | |
| else | ||
| enterParamRef(lam.resType) | ||
| | ||
| // for CaseType `case Array[t] => t` which is represented as [t] =>> MatchCase[Array[t], t] | ||
| case m: MatchType => | ||
| m.cases.foreach(enterParamRef) | ||
| | ||
| // for class constructor | ||
| // class C[T] { ... } | ||
| case cls: ClassInfo if sym.info.isInstanceOf[LambdaType] => | ||
| | @@ -228,6 +233,14 @@ class TypeOps: | |
| val ssym = sym.symbolName | ||
| s.TypeRef(spre, ssym, Seq.empty) | ||
| | ||
| case TypeRef(pre, sym: Name) => | ||
| // val spre = if tpe.hasTrivialPrefix then s.Type.Empty else loop(pre) | ||
| // Craft semanticdb symbol | ||
| // prefix symbol (e.g. "scala/") + name (e.g. "Nothing") + Global symbol suffix ("#") | ||
| // see: https://scalameta.org/docs/semanticdb/specification.html#symbol | ||
| val ssym = s"${pre.typeSymbol.symbolName}${sym.mangledString}#" | ||
bishabosha marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| s.TypeRef(s.Type.Empty, ssym, Seq.empty) | ||
| ||
| | ||
| case TermRef(pre, sym: Symbol) => | ||
| val spre = if(tpe.hasTrivialPrefix) s.Type.Empty else loop(pre) | ||
| val ssym = sym.symbolName | ||
| | @@ -276,6 +289,31 @@ class TypeOps: | |
| case ConstantType(const) => | ||
| s.ConstantType(const.toSemanticConst) | ||
| | ||
| case matchType: MatchType => | ||
| val scases = matchType.cases.map { caseType => caseType match { | ||
| case lam: HKTypeLambda => // case Array[t] => t | ||
| val paramSyms = lam.paramNames.flatMap { paramName => | ||
| val key = (lam, paramName) | ||
| paramRefSymtab.get(key) | ||
| }.sscope | ||
| lam.resType match { | ||
| case defn.MatchCase(key, body) => | ||
| s.MatchType.CaseType( | ||
| loop(key), | ||
| loop(body) | ||
| ) | ||
| case _ => s.MatchType.CaseType() // shouldn't happen | ||
| } | ||
| case defn.MatchCase(key, body) => | ||
| val skey = loop(key) | ||
| val sbody = loop(body) | ||
| s.MatchType.CaseType(skey, sbody) | ||
| case _ => s.MatchType.CaseType() // shouldn't happen | ||
| }} | ||
| val sscrutinee = loop(matchType.scrutinee) | ||
| val sbound = loop(matchType.bound) | ||
| s.MatchType(sscrutinee, scases) | ||
| | ||
| case rt @ RefinedType(parent, name, info) => | ||
| // `X { def x: Int; def y: Int }` | ||
| // RefinedType( | ||
| | @@ -405,8 +443,6 @@ class TypeOps: | |
| // Not yet supported | ||
| case _: HKTypeLambda => | ||
| s.Type.Empty | ||
| case _: MatchType => | ||
| s.Type.Empty | ||
| | ||
| case tvar: TypeVar => | ||
| loop(tvar.stripped) | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
!tree.symbol.isTypehere, to misinterpret the type variable symbol asValThis change makes type variables like
local0 => case val method N$1 <: Nattolocal0 => case type N$1 <: Nat.Other diffs: just indented.