Skip to content

[ Typechecker ] Message when passing A where B is expected when A and B are newtypes does not mention A, just ?nonnull #8832

@lexidor

Description

@lexidor

Describe the bug
Message when passing KindOfHerp where KindOfDerp is expected when KindOfHerp and KindOfDerp are newtypes does not mention KindOfHerp. Instead it says that the newtype is constrained to ?nonnull a.k.a. mixed.

Standalone code, or other way to reproduce the problem

// file1.hack
newtype KindOfHerp = string;
newtype KindOfDerp = string;

function herp(): KindOfHerp {
    return 'KindOfHerp';
}

// file2.hack
function derp(): KindOfDerp {
    return herp();
}

Steps to reproduce the behavior:

  1. hh_client

Expected behavior

Typing[4110] Invalid return type [1]
-> Expected KindOfDerp [2]
-> But got KindOfHerp [3]

Actual behavior

Typing[4110] Invalid return type [1]
-> Expected KindOfDerp [2]
-> But got mixed arising from an implicit as ?nonnull constraint on this type [3]

Environment

  • Operating system

Ubuntu 18.04

  • Installation method

apt-get with dl.hhvm.com repository

  • HHVM Version
HipHop VM 4.107.0 (rel)
Compiler: 1619546863_111004381
Repo schema: d1ae8e21bf3419a65f12a010527485564e719d07
hackc-c7fffd36e382b7f28420653e7a0f0e78e61342a8-4.107.0

Additional context

The full error message, annotated with ^^^^ in highlighted parts of the error.

Typing[4110] Invalid return type [1]
-> Expected KindOfDerp [2]
-> But got mixed arising from an implicit as ?nonnull constraint on this type [3]

file1.hack:-:-
      | 
[2]   | function derp(): KindOfDerp {
                         ^^^^^^^^^^
[1]   |     return herp();
                   ^^^^^^
      | }

file2.hack:-:-
      | newtype KindOfDerp = string;
      | 
[3]   | function herp(): KindOfHerp {
                         ^^^^^^^^^^
      |     return 'KindOfHerp';
      | }

1 error found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions