|
| 1 | +package dotty.tools |
| 2 | +package dotc |
| 3 | +package transform |
| 4 | + |
| 5 | +import core.* |
| 6 | +import Contexts.*, Decorators.*, Denotations.*, SymDenotations.*, Symbols.*, Types.* |
| 7 | +import Annotations.* |
| 8 | + |
| 9 | +import org.junit.Test |
| 10 | +import org.junit.Assert.* |
| 11 | + |
| 12 | +class TypeTestsCastsTest extends DottyTest: |
| 13 | + val defn = ctx.definitions; import defn.* |
| 14 | + |
| 15 | + @Test def orL = checkFound(List(StringType, LongType), OrType(LongType, StringType, false)) |
| 16 | + @Test def orR = checkFound(List(LongType, StringType), OrType(StringType, LongType, false)) |
| 17 | + |
| 18 | + @Test def annot = checkFound(List(StringType, LongType), AnnotatedType(OrType(LongType, StringType, false), Annotation(defn.UncheckedAnnot))) |
| 19 | + |
| 20 | + @Test def andL = checkFound(List(StringType), AndType(StringType, AnyType)) |
| 21 | + @Test def andR = checkFound(List(StringType), AndType(AnyType, StringType)) |
| 22 | + @Test def andX = checkFound(List(NoType), AndType(StringType, BooleanType)) |
| 23 | + |
| 24 | + // (A | B) & C => {(A & B), (A & C)} |
| 25 | + // A & (B | C) => {(A & B), (A & C)} |
| 26 | + // (A | B) & (C | D) => {(A & C), (A & D), (B & C), (B & D)} |
| 27 | + @Test def orInAndL = checkFound(List(StringType, LongType), AndType(OrType(LongType, StringType, false), AnyType)) |
| 28 | + @Test def orInAndR = checkFound(List(StringType, LongType), AndType(AnyType, OrType(LongType, StringType, false))) |
| 29 | + @Test def orInAndZ = |
| 30 | + // (Throwable | Exception) & (RuntimeException | Any) = |
| 31 | + // Throwable & RuntimeException = RuntimeException |
| 32 | + // Throwable & Any = Throwable |
| 33 | + // Exception & RuntimeException = RuntimeException |
| 34 | + // Exception & Any = Exception |
| 35 | + val ExceptionType = defn.ExceptionClass.typeRef |
| 36 | + val RuntimeExceptionType = defn.RuntimeExceptionClass.typeRef |
| 37 | + val tp = AndType(OrType(ThrowableType, ExceptionType, false), OrType(RuntimeExceptionType, AnyType, false)) |
| 38 | + val exp = List(ExceptionType, RuntimeExceptionType, ThrowableType, RuntimeExceptionType) |
| 39 | + checkFound(exp, tp) |
| 40 | + |
| 41 | + def checkFound(found: List[Type], tp: Type) = |
| 42 | + val expected = found.map(_.classSymbol) |
| 43 | + val obtained = TypeTestsCasts.foundClasses(tp) |
| 44 | + assertEquals(expected, obtained) |
| 45 | +end TypeTestsCastsTest |
0 commit comments