D - Compiler bug with char[] and inner functions:
- Daniel Yokomiso (46/46) Apr 21 2003 Hi,
Hi, In the following piece of code, if we comment out the inner function definition inside the unittest everything is fine. If not the compiler can't match the delegate type. module bug2; alias bit boolean; template TArrays(T) { public boolean all(T[] array, boolean (*predicate)(T)) { for (int i = 0; i < array.length; i++) { if (!predicate(array[i])) { return false; } } return true; } } boolean isVowel(char c) { return (c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'); } unittest { boolean isVowel(char c) { return (c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'); } instance TArrays(char) arrays; assert(arrays.all("aeiouoeieuiei", &isVowel)); assert(arrays.all("aeoiuaioeuioaeuiouoiaeu", &isVowel)); assert(!arrays.all("aaeiouioeujiurioue", &isVowel)); assert(!arrays.all("bjkqwkjbwqjbkwb", &isVowel)); assert(arrays.all("", &isVowel)); printf("TArrays(char).all tests passed!\r\n"); } int main() { return 0; } Best regards, Daniel Yokomiso. "Computer games don't affect kids; I mean if Pac Man affected us as kids, we would all be running around in darkened rooms, munching magic pills, and listening to repetitive electronic music." - Kristian Wilson, Nintendo Inc. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.474 / Virus Database: 272 - Release Date: 18/4/2003
Apr 21 2003