basename
and size
should have explicit String
overloads
#683
Labels
S02-needs-owner
(State) An issue that needs an individual to write an RFC.
T-stdlib
(Topic) Issues related to the standard library.
The
basename
functionCurrently the
basename
function has two overloads defined in the spec:But it then goes on to say:
The issue here is that
String
is coercible to bothFile
andDirectory
and so calling it with aString
is technically ambiguous; the ambiguity was introduced with the addition of theDirectory
type in 1.2.An ambiguity like that makes it more difficult to do the type calculus on an expression in a generic way, especially for function calls that may have type parameters. While in this specific case, we know that
basename("foo")
has typeString
for its expression because all of the overloads that are ambiguous returnString
, that may not be the case for some other function where the overloads differ on return type. In both cases I would want my type calculator to report on the ambiguity in binding the function arguments.Additionally, depending on how an engine is implemented, it might not be possible to know what the "original" type was following a coercion, so it might prove difficult to fulfill the requirement of "If the argument is a String, it is assumed to be a local file path relative to the current working directory of the task." unless the engine knows the call was dispatched to the
String
overload of the function.I propose we add the following overload to
basename
and amend its parameter description toString|File|Directory
:The
size
functionThe
size
For the same reason as above, a call with
String
for the first argument would be ambiguous between all the first two overloads only; it would not bind to the third overload due to the type constraint onX
(any compound type that contains File or File? nested at any depth
), asString
does not satisfy that constraint.Thus, I propose adding this additional overload:
We should also include the same note as that for
baseline
regarding theString
overload, i.e. "If the argument is a String, it is assumed to be a local file path relative to the current working directory of the task."The text was updated successfully, but these errors were encountered: