-
Notifications
You must be signed in to change notification settings - Fork 338
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
bugfix: Remove PrettyType which might often fail in the compiler #5763
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,20 +252,6 @@ class MetalsGlobal( | |
} | ||
} | ||
|
||
/** | ||
* A `Type` with custom pretty-printing representation, not used for typechecking. | ||
* | ||
* NOTE(olafur) Creating a new `Type` subclass is a hack, a better long-term solution would be | ||
* to implement a custom pretty-printer for types so that we don't have to rely on `Type.toString`. | ||
*/ | ||
class PrettyType( | ||
override val prefixString: String, | ||
override val safeToString: String | ||
) extends Type { | ||
def this(string: String) = | ||
this(string + ".", string) | ||
} | ||
|
||
private def backtickify(sym: Symbol) = | ||
if ( | ||
Identifier.needsBacktick(sym.name.decoded) | ||
|
@@ -294,11 +280,19 @@ class MetalsGlobal( | |
isVisited += key | ||
val result = tpe match { | ||
case TypeRef(pre, sym, args) => | ||
def backtickifiedSymbol = backtickify(sym) | ||
def shortSymbol = { | ||
/* If it's an alias type we want to prevent dealiasing it | ||
AnyRef should stay to be dropped if neded later on since it's | ||
not an important class. | ||
*/ | ||
if (sym.isAliasType && sym != definitions.AnyRefClass) | ||
backtickify(sym.newErrorSymbol(sym.name).updateInfo(sym.info)) | ||
else backtickify(sym) | ||
} | ||
if (history.isSymbolInScope(sym, pre)) { | ||
TypeRef( | ||
NoPrefix, | ||
backtickifiedSymbol, | ||
shortSymbol, | ||
args.map(arg => loop(arg, None)) | ||
) | ||
} else { | ||
|
@@ -324,8 +318,11 @@ class MetalsGlobal( | |
history.config.get(ownerSymbol) match { | ||
case Some(rename) if canRename(rename, ownerSymbol) => | ||
TypeRef( | ||
new PrettyType(rename.toString), | ||
backtickifiedSymbol, | ||
SingleType( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacing PrettyType with SingleType wa enough except for CompletionWorkspaceSuite.type-import where the type would alwyas be dealiased when printing. So I changed the symbol to always be error in shortened type. |
||
NoPrefix, | ||
sym.newErrorSymbol(rename) | ||
), | ||
shortSymbol, | ||
args.map(arg => loop(arg, None)) | ||
) | ||
case _ => | ||
|
@@ -352,20 +349,20 @@ class MetalsGlobal( | |
if (history.nameResolvesToSymbol(sym.name, sym)) { | ||
TypeRef( | ||
NoPrefix, | ||
backtickifiedSymbol, | ||
shortSymbol, | ||
args.map(arg => loop(arg, None)) | ||
) | ||
} else { | ||
TypeRef( | ||
ThisType(pre.typeSymbol), | ||
backtickifiedSymbol, | ||
shortSymbol, | ||
args.map(arg => loop(arg, None)) | ||
) | ||
} | ||
} else { | ||
TypeRef( | ||
loop(pre, Some(ShortName(sym))), | ||
backtickifiedSymbol, | ||
shortSymbol, | ||
args.map(arg => loop(arg, None)) | ||
) | ||
} | ||
|
@@ -424,7 +421,10 @@ class MetalsGlobal( | |
} | ||
else renamedOwnerIndex | ||
if (prefix < 0) { | ||
new PrettyType(history.fullname(sym)) | ||
SingleType( | ||
NoPrefix, | ||
sym.newErrorSymbol(TypeName(history.fullname(sym))) | ||
) | ||
} else { | ||
val names = owners | ||
.take(prefix + 1) | ||
|
@@ -440,7 +440,10 @@ class MetalsGlobal( | |
val ref = names.tail.foldLeft(names.head: m.Term.Ref) { | ||
case (qual, name) => m.Term.Select(qual, name) | ||
} | ||
new PrettyType(ref.syntax) | ||
SingleType( | ||
NoPrefix, | ||
sym.newErrorSymbol(TypeName(ref.syntax)) | ||
) | ||
} | ||
} | ||
case ConstantType(Constant(sym: TermSymbol)) | ||
|
@@ -464,7 +467,11 @@ class MetalsGlobal( | |
// [x] => F[x] is not printable in the code, we need to use just `F` | ||
case TypeRef(_, sym, args) | ||
if typeParams == args.map(_.typeSymbol) => | ||
new PrettyType(sym.name.toString()) | ||
TypeRef( | ||
NoPrefix, | ||
sym.newErrorSymbol(sym.name), | ||
Nil | ||
) | ||
case otherType => | ||
PolyType(typeParams, otherType) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This makes sure that sym is not dealiased ince the error type is not an alias, but we still have all the correct type info.