javascript - Can a regular expression be crafted which determines the return type of a function? -


given text of following function:

function f3() {   return math.random() > 0.5 ? promise.resolve(true): 'naaah' } 

can regular expression compiled determines return type of f3() call, without calling function?

given code, cannot determine return type of via regular expressions. proof contradiction:

  1. assume can find return type using regular expression.

  2. the return type decided in final line, via non-deterministic call random (it isn't known ahead of time).

  3. regular expressions deterministic- have same output when run on same input.

  4. thus, function's return type must static, since can run regular expression , find return type (and regular expression return same thing).

  5. contradiction: function's return type must static, function's return type variable due random

note: above assumes type must single one, , not account union types on own.

additionally, proof on why can't always.

  1. assume somehow can figure out every type used in function in way.

  2. at point, generate string a="a"+math.random()

  3. at later point, generate string b="class "+a+"{...}

  4. after definition, execute c= eval("new "+a+"()").

  5. when return c, no regular expression can know type- type newly named in function, determined randomly , different every execution.

this assumes question more general "can javascript regex find return type of generic function." note if possible find return type, possible tell program halts (it can't return if doesn't halt, , return type have undefined if never halts), , halting problem still unsolved.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -