Gale Paeper wrote:
To clarify, you are questioning the legality of just ord(substr((s),1,1))?
Yes (my reference was unclear, indeed).
If so, after posting my original internal compiler error message, it dawned on me that perhaps I was pushing the type compatibility rules too far and that the error was due to stressing the compiler with possibly an illegal construct which it was unable to deal with. Therefore, to remove uncetainties about char-type string-type type compatibilities and the ord function, I tried the array indexed form for the constant-expression but, unfortunately, that form also resulted in an internal compiler error. This prompted the run-time expression investigation and the above reported results.
Given the mixture of error results, I was in the process of determining exactly what should be legal according to standard requirements when I saw the fix patch posting which in essense said problem solved so I didn't pursue the legality question any further.
At that time I thought it was ok. When dealing with string constants, it's known at compile time whether or not they have length 1 (i.e., whether or not they could, apparently, be a Char value), so all seemed well. With the clarifications below, this part actually gets more difficult, since there are string constants of length 1 that can or cannot be Char values ...
But for non-constant expressions, things get easier, since it would appear strange if it wasn't known until runtime whether they were ordinal values and would have added a lot of checks (not only in Ord, also in Succ, Pred, High, Low, FillChar, Include, Exclude, Seek..., and perhaps more).
Am I missing something?
I don't think you are. Since the ord argument requirement is specified with expression and not parameter terms and the expression "substr((s),1,1)" is of type canonicalÂstringÂtype which isn't an ordinal-type, "substr((s),1,1)" is an illegal argument for ord since it doesn't satisfy the ordinal-type expression requirement. ("substr((s),1,1)[1]" is legal since the individual components of string-types are char-types which is an ordinal-type and thus the expression is of ordinal-type.)
You're still left with two constant-expression internal compiler errors which need to be fixed.
- For constant-expression ord(substr((s),1,1)), detecting that it isn't
an ordinal expression and issuing an appropriate error message.
(gale1b.pas)
- For constant-expression ord(substr((s),1,1)[1]), evaluating the
expression with a result of the ordinal-value of the first character in the constant-string "s".
(gale1a.pas)
(Also adding gale1[cd].pas for variables instead of constants.)
I'm not sending a patch now, because there were several changes, and I don't remember exactly which ones were necessary or might have broken other things I've fixed meanwhile. I hope it won't be too long till the next release.
Please check if the test programs seem alright now.
Frank