Repository: scalacenter/tasty-query (scala)

Issue:
java.lang.UnsupportedOperationException: TypeTreeTypeTest is not a simple name
Somewhere in the tree of `class impl.QuoteMatcher`, there is:
```
Select(New(TypeIdent(TypeTreeTypeTest)),<init>[with sig ():scala.quoted.runtime.impl.QuoteMatcher._$TypeTreeTypeTest @<init>])
```

If we call `.symbol` on it, it throws:
```
java.lang.UnsupportedOperationException: TypeTreeTypeTest is not a simple name
	at tastyquery.Names$DerivedName.asSimpleName(Names.scala:218)
	at tastyquery.Symbols$ClassSymbol.computeErasedName$1(Symbols.scala:1012)
	at tastyquery.Symbols$ClassSymbol.signatureName(Symbols.scala:1019)
	at tastyquery.Types$ErasedTypeRef.toSigFullName(Types.scala:142)
	at tastyquery.Signatures$Signature$.rec$1(Signatures.scala:44)
	at tastyquery.Signatures$Signature$.fromType(Signatures.scala:47)
	at tastyquery.Symbols$TermSymbol.signature(Symbols.scala:544)
	at tastyquery.Symbols$TermSymbol.signedName(Symbols.scala:582)
	at tastyquery.Symbols$ClassSymbol.distinguishOverloaded$$anonfun$1(Symbols.scala:1188)
	at scala.collection.IterableOnceOps.find(IterableOnce.scala:635)
	at scala.collection.IterableOnceOps.find$(IterableOnce.scala:631)
	at scala.collection.AbstractIterable.find(Iterable.scala:933)
	at tastyquery.Symbols$ClassSymbol.distinguishOverloaded(Symbols.scala:1191)
	at tastyquery.Symbols$ClassSymbol.getDecl(Symbols.scala:1172)
	at tastyquery.Symbols$ClassSymbol.findMember(Symbols.scala:1481)
	at tastyquery.Types$TermRef$.resolveLookupIn(Types.scala:1138)
	at tastyquery.Types$TermRef.resolve(Types.scala:1049)
	at tastyquery.Types$TermRef.ensureResolved(Types.scala:1033)
	at tastyquery.Types$TermRef.symbol(Types.scala:1029)
	at tastyquery.Trees$TermReferenceTree.symbol(Trees.scala:288)
```

Pull request:

Patch:
diff --git a/tasty-query/shared/src/main/scala/tastyquery/Symbols.scala b/tasty-query/shared/src/main/scala/tastyquery/Symbols.scala
index c6ca1e6c..d462848a 100644
--- a/tasty-query/shared/src/main/scala/tastyquery/Symbols.scala
+++ b/tasty-query/shared/src/main/scala/tastyquery/Symbols.scala
@@ -1017,7 +1017,9 @@ object Symbols {
 
         case owner: TermOrTypeSymbol =>
           // Replace non-class non-package owners by simple `_$`
-          val filledName = name.toTermName.asSimpleName.prepend("_$").toTypeName
+          val filledName =
+            if name.wrapsObjectName then name.sourceObjectName.prepend("_$").withObjectSuffix.toTypeName
+            else name.toTermName.asSimpleName.prepend("_$").toTypeName
           computeErasedName(owner.owner, filledName)
       end computeErasedName
 


Test patch:
diff --git a/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala b/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
index bc3e59df..9f0431df 100644
--- a/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
+++ b/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
@@ -358,4 +358,27 @@ class SignatureSuite extends UnrestrictedUnpicklingSuite:
     assertSigned(takeEmptyTupleSig, "(scala.Tuple$package.EmptyTuple):scala.Unit")
   }
 
+  testWithContext("local object") {
+    // #357
+    val LocalObjectClass = ctx.findTopLevelClass("simple_trees.LocalObject")
+
+    val methodBody = LocalObjectClass.findNonOverloadedDecl(termName("method")).tree.get.asInstanceOf[DefDef].rhs.get
+
+    val myLocalObjectClass = findTree(methodBody) {
+      case ClassDef(_, _, sym) if sym.isModuleClass => sym
+    }
+
+    val fooMethod = findTree(methodBody) { case DefDef(SimpleName("foo"), _, _, _, sym) =>
+      sym
+    }
+    assertSigned(fooMethod, "(simple_trees.LocalObject._$MyLocalObject):simple_trees.LocalObject._$MyLocalObject")
+
+    val (fooSelect, expectedSig) = findTree(methodBody) {
+      case Apply(select @ Select(This(_), SignedName(SimpleName("foo"), sig, _)), _) => (select, sig)
+    }
+
+    assert(clue(fooMethod.signature) == clue(expectedSig))
+    assert(clue(fooSelect.symbol) == clue(fooMethod))
+  }
+
 end SignatureSuite
diff --git a/test-sources/src/main/scala/simple_trees/LocalObject.scala b/test-sources/src/main/scala/simple_trees/LocalObject.scala
new file mode 100644
index 00000000..46f5695c
--- /dev/null
+++ b/test-sources/src/main/scala/simple_trees/LocalObject.scala
@@ -0,0 +1,12 @@
+package simple_trees
+
+class LocalObject:
+  def method(): Unit =
+    object MyLocalObject
+
+    class Inner:
+      def foo(obj: MyLocalObject.type): MyLocalObject.type = obj
+
+      foo(MyLocalObject)
+  end method
+end LocalObject