Early Error in annex semantics of GlobalDeclarationInstantiation

I couldn't find any sources speaking about the next point in specification (let it be GlobalDeclarationInstantiation):

ii. If replacing the FunctionDeclaration f with a VariableStatement that has F as a BindingIdentifier would not produce any Early Errors for script, then

I don't understand this step, what would it be demonstrating this error?

I am trying to figure out this step in annex. So if we don't do replacements FunctionDeclartion with the VariableStatement, we won't get the error. Conversily we will get the error, if we do this replacements. What is example of it then?


Solution 1:

The only of the Script early errors that I can see possibly applying to that replacement is

It is a Syntax Error if any element of the LexicallyDeclaredNames of ScriptBody also occurs in the VarDeclaredNames of ScriptBody.

So let's assume the script

let x = 42;
{
  function x() {}
  console.log('block', typeof x);
}
console.log('global', typeof x, typeof window.x);

Now if we did replace the function declaration with the respective variable declaration, we'd get the script

let x = 42;
{
  var x;
  console.log('block', typeof x);
}
console.log('global', typeof x, typeof window.x);

which causes a syntax error. So it does not run the conditional steps to create a global variable for the function.

If there is no collision with the lexical variables declared by the same script, the legacy web compatibility semantics do take effect:

let y = 42;
{
  function x() {}
  console.log('block', typeof x);
}
console.log('global', typeof x, typeof window.x);