(Context ctx)
| 883 | // / Some basic expression casting tests. |
| 884 | |
| 885 | void castingTest(Context ctx) throws TestFailedException |
| 886 | { |
| 887 | System.out.println("CastingTest"); |
| 888 | |
| 889 | Sort[] domain = { ctx.getBoolSort(), ctx.getBoolSort() }; |
| 890 | FuncDecl f = ctx.mkFuncDecl("f", domain, ctx.getBoolSort()); |
| 891 | |
| 892 | AST upcast = ctx.mkFuncDecl(ctx.mkSymbol("q"), domain, |
| 893 | ctx.getBoolSort()); |
| 894 | |
| 895 | try |
| 896 | { |
| 897 | @SuppressWarnings("unused") |
| 898 | FuncDecl downcast = (FuncDecl) f; // OK |
| 899 | } catch (ClassCastException e) |
| 900 | { |
| 901 | throw new TestFailedException(); |
| 902 | } |
| 903 | |
| 904 | try |
| 905 | { |
| 906 | @SuppressWarnings("unused") |
| 907 | Expr uc = (Expr) upcast; |
| 908 | throw new TestFailedException(); // should not be reachable! |
| 909 | } catch (ClassCastException e) |
| 910 | { |
| 911 | } |
| 912 | |
| 913 | Symbol s = ctx.mkSymbol(42); |
| 914 | IntSymbol si = (s.getClass() == IntSymbol.class) ? (IntSymbol) s : null; |
| 915 | if (si == null) |
| 916 | throw new TestFailedException(); |
| 917 | try |
| 918 | { |
| 919 | @SuppressWarnings("unused") |
| 920 | IntSymbol si2 = (IntSymbol) s; |
| 921 | } catch (ClassCastException e) |
| 922 | { |
| 923 | throw new TestFailedException(); |
| 924 | } |
| 925 | |
| 926 | s = ctx.mkSymbol("abc"); |
| 927 | StringSymbol ss = (s.getClass() == StringSymbol.class) ? (StringSymbol) s |
| 928 | : null; |
| 929 | if (ss == null) |
| 930 | throw new TestFailedException(); |
| 931 | try |
| 932 | { |
| 933 | @SuppressWarnings("unused") |
| 934 | StringSymbol ss2 = (StringSymbol) s; |
| 935 | } catch (ClassCastException e) |
| 936 | { |
| 937 | throw new TestFailedException(); |
| 938 | } |
| 939 | try |
| 940 | { |
| 941 | @SuppressWarnings("unused") |
| 942 | IntSymbol si2 = (IntSymbol) s; |
no test coverage detected