After thinking a bit more I have concluded its important consistency issue. So I reposted it as separate issue.
import std.stdio;
void f(S)(S str){
writeln(str);
}
alias f!(string) fc;
alias f!(wstring) fc;
void main(){
fc("foo"); // L11
//~ fc("foo"c); // works
//~ auto s = "foo";
//~ fc(s); // works
}
//~ Compilation (dmd 2.055) breaks with message:
//~ bug.d(11): Error: function alias bug.f called with argument types:
//~ ((string))
//~ matches both:
//~ bug.f!(string).f(string str)
//~ and:
//~ bug.f!(immutable(wchar)[]).f(immutable(wchar)[] str)
Maybe lexer should annotate string literal without StringPostfix according source code format?
Comment #1 by yebblies — 2011-09-10T06:42:26Z
It should work the same for function calls as it does for type deduction: an untyped string literal should default to immutable(char)[].
Fortunately there's already a patch for this.
*** This issue has been marked as a duplicate of issue 2367 ***
Comment #2 by zeljko.grk — 2011-09-10T08:12:58Z
Sorry for duplication.
My point is maybe we don’t need unannotated string literal out of lexer.
Maybe c is better default, but we need simple rule.
Confess I’m not aware of all consequences.
Something to think about, maybe?
Comment #3 by yebblies — 2011-09-10T08:36:14Z
(In reply to comment #2)
> My point is maybe we don’t need unannotated string literal out of lexer.
> Maybe c is better default, but we need simple rule.
>
> Confess I’m not aware of all consequences.
> Something to think about, maybe?
We actually do need it to be initially untyped. If every string literal was implicitly utf-8, the following functions could not be called with a literal:
void fun(wstring s);
void fun(dstring s);
void fun(const(char)* s);
What is important is that a default type can be automatically used, and it already works this way some of the time.
auto x = "blah blah"; // x is typed as string
Extending this default type to function calls seems natural to me.