Skip to content

Typehint for Str\format() should be string, not HH\FormatString #3

@Andi-K

Description

@Andi-K

I get this Error:

Fatal error: Uncaught TypeError: Argument 1 passed to HH\Lib\Str\format() must be an instance of HH\FormatString, string given, called in [...]/hacktophp/generated-php/src/__Private/SubprocessException.php on line 25 and defined in [...]/hsl-php/generated-php/src/str/format.php on line 157

This is because

<?hh

type SprintfFormatString = \HH\FormatString<SprintfFormat>;

<<__Rx>>
function format(
  SprintfFormatString $format_string,
  mixed ...$format_args
): string {
  /* HH_IGNORE_ERROR[2049] __PHPStdLib */
  /* HH_IGNORE_ERROR[4107] __PHPStdLib */
  return \vsprintf($format_string, $format_args);
}

is converted to

<?php

/**
 * @param \HH\FormatString<SprintfFormat> $format_string
 * @param mixed ...$format_args
 */
function format(\HH\FormatString $format_string, ...$format_args) : string
{
    return \vsprintf($format_string, $format_args);
}

So far actually right, only FormatString is not a class.
It is builtin code?
/tmp/hh_server/hhi_833e78d/typenames.hhi:

namespace HH {
  newtype FormatString<T> = string;
}

I don't know if you can autodetect such special cases

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions