Files
swift-mirror/validation-test/stdlib/NumericDiagnostics.swift.gyb
Flash Sheridan 3a074e5a50 Assign the result of binary operations to a variable, in preparation for checking its type in my next check-in.
Ugly (both in layout and functionality) workaround for Gyb rdar://15928178, using operator if/else if/else instead of if/elif statements;
this was fiddly to get working, hence the separate check-in.
Sharpen the expected error string for mixed type operators, and add an expected warning and note for assigning the result of
an assignment, which is righteous since we're not C.
Approved by Dmitri.


Swift SVN r24586
2015-01-21 03:54:48 +00:00

45 lines
2.2 KiB
Plaintext

// RUN: rm -rf %t && mkdir -p %t && %S/../../utils/gyb %s -o %t/main.swift
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift -parse -Xfrontend -verify %t/main.swift
% from SwiftIntTypes import all_numeric_type_names, numeric_type_names_Macintosh_only, \
% all_integer_type_names,all_integer_binary_operator_names, all_integer_or_real_binary_operator_names, \
% all_arithmetic_comparison_operator_names, all_integer_assignment_operator_names, \
% all_integer_or_real_assignment_operator_names
% int_ops = all_integer_binary_operator_names() + all_integer_assignment_operator_names()
% arith_ops = all_integer_or_real_binary_operator_names() + \
% all_arithmetic_comparison_operator_names() + all_integer_or_real_assignment_operator_names()
% count = 0
//TODO: Verify the type of the result
func testIteratedOperations() {
% for typesToTest, operatorsToTest in zip([all_integer_type_names(), all_numeric_type_names()], \
% [int_ops, arith_ops]):
% operatorsToTest = [x for x in operatorsToTest if not '+' in x and not '-' in x]
%# TODO: rm when rdar://18695154 is fixed.
// typesToTest: ${typesToTest}, operatorsToTest: ${operatorsToTest}
% for T1 in typesToTest:
% for T2 in typesToTest:
${ "\n\n#if arch(i386) || arch(x86_64)\n" if T1 in numeric_type_names_Macintosh_only()
or T2 in numeric_type_names_Macintosh_only() else "" }
% for op in operatorsToTest:
% count += 1
% theDiagnostic = "// expected-error{{of type}}" if (T1 != T2) else \
% "// expected-note{{add an explicit type annotation}} expected-warning{{inferred to have type}}"\
% if (op in all_integer_assignment_operator_names() + all_integer_or_real_assignment_operator_names())\
% else "" #FIXME Temporary workaround for rdar://15928178 gyb miscompiles nested if elif
if true { // ${count}
var x1_${T1}: ${T1} = 0
var x2_${T2}: ${T2} = 0
var result = x1_${T1} ${op} x2_${T2} ${theDiagnostic}
}
%end # op
${ "\n#endif //arch(i386) || arch(x86_64)\n\n" if T1 in numeric_type_names_Macintosh_only()
or T2 in numeric_type_names_Macintosh_only() else "" }
%end # T2
%end # T1
%end # typesToTest
}