Skip to content

Commit

Permalink
Merge pull request #364 from sjrd/add-tests-from-old-branches
Browse files Browse the repository at this point in the history
Add tests from old branches
  • Loading branch information
bishabosha authored Oct 18, 2023
2 parents 68dbaac + f22cc58 commit 8416e61
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,8 @@ class SubtypingSuite extends UnrestrictedUnpicklingSuite:
val GenIterableClass = ctx.findTopLevelClass("scala.collection.Iterable")
val ImmutableIterableClass = ctx.findTopLevelClass("scala.collection.immutable.Iterable")
val MutableIterableClass = ctx.findTopLevelClass("scala.collection.mutable.Iterable")
val MapClass = ctx.findTopLevelClass("scala.collection.Map")
val ImmutableMapClass = ctx.findTopLevelClass("scala.collection.immutable.Map")

// No withRef's because these are not proper types

Expand All @@ -1191,6 +1193,13 @@ class SubtypingSuite extends UnrestrictedUnpicklingSuite:
assertStrictSubtype(MutableIterableClass.staticRef, GenIterableClass.staticRef)

assertNeitherSubtype(ImmutableIterableClass.staticRef, MutableIterableClass.staticRef)

assertEquiv(ListClass.staticRef, ListClass.staticRef)
assertStrictSubtype(ListClass.staticRef, defn.SeqTypeUnapplied)
assertNeitherSubtype(ListClass.staticRef, OptionClass.staticRef)

assertStrictSubtype(ImmutableMapClass.staticRef, MapClass.staticRef)
assertNeitherSubtype(ImmutableMapClass.staticRef, GenIterableClass.staticRef)
}

testWithContext("annotated-types") {
Expand Down
43 changes: 31 additions & 12 deletions tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1484,21 +1484,11 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
val optBaseType = origType.baseType(IterableOpsClass) // this used to cause an infinite recursion
assert(optBaseType.isDefined)

extension (tpe: TypeOrWildcard)
def andParts: List[Type] = tpe match
case tpe: AndType => tpe.parts
case tpe: Type => tpe :: Nil
case _: WildcardTypeArg => Nil

// sc.IterableOps[scala.Int, (... & sci.List), sci.List[scala.Int]]
// sc.IterableOps[scala.Int, sci.List, sci.List[scala.Int]]
assert(
optBaseType.get.isApplied(
_.isRef(IterableOpsClass),
List(
_.isRef(defn.IntClass),
_.andParts.exists(_.isRef(ListClass)),
_.isApplied(_.isRef(ListClass), List(_.isRef(defn.IntClass)))
)
List(_.isRef(defn.IntClass), _.isRef(ListClass), _.isApplied(_.isRef(ListClass), List(_.isRef(defn.IntClass))))
)
)

Expand Down Expand Up @@ -3166,4 +3156,33 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
checkTypes(findCall("mhUnit"), List(defn.StringType), defn.UnitType)
checkTypes(findCall("mhObj"), List(defn.StringType), defn.AnyType)
}

testWithContext("java-shadowing-inner-class") {
val JavaShadowingClassParentClass = ctx.findTopLevelClass("javadefined.JavaShadowingClassParent")
val JavaShadowingClassChildClass = ctx.findTopLevelClass("javadefined.JavaShadowingClassChild")

val ParentInnerClass = JavaShadowingClassParentClass.findDecl(typeName("InnerClass")).asClass
val ChildInnerClass = JavaShadowingClassChildClass.findDecl(typeName("InnerClass")).asClass
assert(clue(ParentInnerClass) != clue(ChildInnerClass))

val JavaClassShadowingClass = ctx.findTopLevelClass("simple_trees.JavaClassShadowing")

val testSym = JavaClassShadowingClass.findNonOverloadedDecl(termName("test"))
val useParentInnerSym = JavaClassShadowingClass.findNonOverloadedDecl(termName("useParentInner"))
val useChildInnerSym = JavaClassShadowingClass.findNonOverloadedDecl(termName("useChildInner"))

val DefDef(_, _, _, Some(body), _) = testSym.tree.get: @unchecked

val parentInnerSym = findTree(body) { case ValDef(SimpleName("parentInner"), _, _, sym) =>
sym
}
assert(clue(parentInnerSym.localRef.underlying).isRef(ParentInnerClass))
assert(!clue(parentInnerSym.localRef.underlying).isRef(ChildInnerClass))

val childInnerSym = findTree(body) { case ValDef(SimpleName("childInner"), _, _, sym) =>
sym
}
assert(!clue(childInnerSym.localRef.underlying).isRef(ParentInnerClass))
assert(clue(childInnerSym.localRef.underlying).isRef(ChildInnerClass))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package javadefined;

public class JavaShadowingClassChild extends JavaShadowingClassParent {
public class InnerClass {
public int bar() {
return 2;
}
}

public InnerClass makeChildInnerClass() {
return new InnerClass();
}

public JavaShadowingClassParent.InnerClass makeOtherParentInnerClass() {
return new JavaShadowingClassParent.InnerClass();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package javadefined;

public class JavaShadowingClassParent {
public class InnerClass {
public int foo() {
return 1;
}
}

public InnerClass makeParentInnerClass() {
return new InnerClass();
}
}
25 changes: 25 additions & 0 deletions test-sources/src/main/scala/simple_trees/JavaClassShadowing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package simple_trees

import javadefined.{JavaShadowingClassChild, JavaShadowingClassParent}

class JavaClassShadowing:
def test(): Unit =
val child: JavaShadowingClassChild = new JavaShadowingClassChild

val parentInner = child.makeParentInnerClass()
useParentInner(parentInner)

// For some reason, this does not compile:
//val otherParentInner = child.makeOtherParentInnerClass()
//useParentInner(otherParentInner)

val childInner = child.makeChildInnerClass()
useChildInner(childInner)
end test

def useParentInner(parentInner: JavaShadowingClassParent#InnerClass): Unit =
()

def useChildInner(childInner: JavaShadowingClassChild#InnerClass): Unit =
()
end JavaClassShadowing

0 comments on commit 8416e61

Please sign in to comment.