(comment on #611) `function g(a, d = (a = 10)) { return a; }` returns the argument instead of 10

Abierto
#618 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 5 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, javascript
Área
compilers

Línea de trabajo

Repro is ./qjs t.js with the g/k/f snippets; run it first to confirm 1 [1,10] and 1. The relevant path is FunctionDeclarationInstantiation: fd->has_parameter_expressions, the argument-scope copy through OP_get_arg and OP_scope_put_var_init, and body lookup via find_var/find_arg falling back to fd->args. Done when g(1) and f(1) print 10 and 5 and existing tests still pass.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

One more from the same run, on master e585640 (2026-11-10) and release 2026-06-04 (./qjs t.js).

3. Parameter assignment in a default initializer (or parameter-scope closure) is not visible in the function body.

function g(a, d = (a = 10)) { return a; }
function k(a, c = () => a, d = (a = 10)) { return [a, c()]; }
console.log(g(1), JSON.stringify(k(1)));
// expected: 10 [10,10]

./qjs t.js prints 1 [1,10]. Because the body has no var a, the parameter list and body share one binding for a (FunctionDeclarationInstantiation steps 27-28), so the assignment a = 10 during d's initializer must be visible in the body. The same happens when a closure created in the parameter list assigns to a later:

function f(a, set = () => { a = 5; }) { set(); return a; }
console.log(f(1));   // expected: 5

./qjs t.js prints 1. When fd->has_parameter_expressions is true, QuickJS copies each plain parameter into a separate JS_VAR_DEF_LET variable in the argument scope (OP_get_arg + OP_scope_put_var_init) so expressions and closures in the parameter list read/write that lexical variable, while the body resolves a to the original fd->args slot via find_var (find_arg) unless a body var shadows it.

Credit: https://ucsbplse.github.io/

Lenguaje dominante
C
Estrellas
11.1k
Forks
1.2k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bellard/quickjs

Todos los issues de bellard/quickjs

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.