godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.04k stars 20.19k forks source link

parse error with typed gdscript #20346

Closed volzhs closed 6 years ago

volzhs commented 6 years ago

Godot version:

3.1.dev 7478649b2

OS/device including version:

Kubuntu 18.04 / Android 8.0 (galaxy s8+)

Issue description:

str() causes parse error with exported game.

SCRIPT ERROR: GDScript::load_byte_code: Parse Error: Too many arguments for '()' call. Expected at most 0.                                                                                           
   At: res://Control.gdc:6.                                                                                                                                                                          
ERROR: load_byte_code: Method/Function Failed, returning: ERR_PARSE_ERROR                                                                                                                            
   At: modules/gdscript/gdscript.cpp:760.                                                                                                                                                            
ERROR: load: Condition ' err != OK ' is true. returned: RES()
   At: modules/gdscript/gdscript.cpp:1939.
ERROR: _load: Failed loading resource: res://Control.gdc
   At: core/io/resource_loader.cpp:186.
ERROR: poll: res://Control.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Control.gd
   At: scene/resources/scene_format_text.cpp:439.
ERROR: load: Condition ' err != OK ' is true. returned: RES()
   At: core/io/resource_loader.cpp:149.
ERROR: _load: Failed loading resource: res://Control.tscn
   At: core/io/resource_loader.cpp:186.
ERROR: start: Failed loading scene: res://Control.tscn
   At: main/main.cpp:1678.
WARNING: cleanup: ObjectDB Instances still exist!
   At: core/object.cpp:1990.
ERROR: clear: Resources Still in use at Exit!
   At: core/resource.cpp:422.

I tested on Linux & Android. Running in editor is fine. I definitely compiled new x11, android templates with latest source code.

Steps to reproduce:

  1. type like this.
    
    extends Control

func _ready(): var n str(n)


2. export it
3. run exported game with **Debug ON**

**_Note that exported with release does not have this issue._**

**Minimal reproduction project:**
<!-- Recommended as it greatly speeds up debugging. Drag and drop a zip archive to upload it. -->
[Test typed gdscript.zip](https://github.com/godotengine/godot/files/2216891/Test.typed.gdscript.zip)
volzhs commented 6 years ago

cc @vnen

jahd2602 commented 6 years ago

Running a project on Android with Godot, 1 commit before https://github.com/godotengine/godot/pull/19264, works fine. After compiling master and testing on Android, I get a similar error:

07-24 11:47:34.419 15303-15337/org.godotengine.jumpingdown E/godot: **SCRIPT ERROR**: Parse Error: Too many arguments for '()' call. Expected at most 0 but called with 3.
       At: res://Scripts/jumpingPlayer.gdc:12:GDScript::load_byte_code() - Parse Error: Too many arguments for '()' call. Expected at most 0 but called with 3.
    **ERROR**: Method/Function Failed, returning: ERR_PARSE_ERROR
       At: modules\gdscript\gdscript.cpp:760:load_byte_code() - Method/Function Failed, returning: ERR_PARSE_ERROR
    **ERROR**: Condition ' err != OK ' is true. returned: RES()
       At: modules\gdscript\gdscript.cpp:1939:load() - Condition ' err != OK ' is true. returned: RES()
    **ERROR**: Failed loading resource: res://Scripts/jumpingPlayer.gdc
       At: core\io\resource_loader.cpp:186:_load() - Method/Function Failed, returning: RES()
    **ERROR**: res://Objects/jumping_down.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Scripts/jumpingPlayer.gd
       At: scene\resources\scene_format_text.cpp:439:poll() - res://Objects/jumping_down.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Scripts/jumpingPlayer.gd
    **ERROR**: Condition ' err != OK ' is true. returned: RES()
       At: core\io\resource_loader.cpp:149:load() - Condition ' err != OK ' is true. returned: RES()
07-24 11:47:34.427 15303-15337/org.godotengine.jumpingdown E/godot: **ERROR**: Failed loading resource: res://Objects/jumping_down.tscn
       At: core\io\resource_loader.cpp:186:_load() - Method/Function Failed, returning: RES()
07-24 11:47:34.442 15303-15337/org.godotengine.jumpingdown E/godot: **ERROR**: Failed loading scene: res://Objects/jumping_down.tscn
       At: main\main.cpp:1678:start() - Condition ' !scene ' is true. returned: false

BTW I changed gdscript_parser.cpp:6527 to get the arg_count

_set_error("Too many arguments for '" + callee_name + "()' call. Expected at most " + itos(arg_types.size()) + " but called with " + itos(arg_count) + ".", p_call->line); // Added arg_count to help debugging

BTW it is working fine in Windows and Linux. The error only happens in Android.

Martinii89 commented 6 years ago

Similar problem also for windows export on version f8e8ac2.

Trying to export the multiplayer bomber demo project gives similar error messages for a debug export. Swapping all the str() calls with string interpolations did not solve the issue though. But might be related.

Minimal setup:

func _ready():
    #load gives critical errors in a export with debug
        #var world = load("res://world.tscn").instance()
    #with preload there is no issue in the export with debug
    var world = preload("res://world.tscn").instance()
    get_tree().get_root().call_deferred("add_child", world)

This script in the startup scene will cause a crash with the following error:

SCRIPT ERROR: GDScript::load_byte_code: Parse Error: Too many arguments for '()' call. Expected at most 0.
          At: res://Node2D.gdc:5
ERROR: load_byte_code: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:760
ERROR: load: Condition ' err != OK ' is true. returned: RES()
   At: modules/gdscript/gdscript.cpp:1939
ERROR: Failed loading resource: res://Node2D.gdc
   At: core/io/resource_loader.cpp:186
ERROR: poll: res://main.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Node2D.gd
   At: scene/resources/scene_format_text.cpp:439
ERROR: load: Condition ' err != OK ' is true. returned: RES()
   At: core/io/resource_loader.cpp:149
ERROR: Failed loading resource: res://main.tscn
   At: core/io/resource_loader.cpp:186
ERROR: Failed loading scene: res://main.tscn
   At: main/main.cpp:1678
WARNING: cleanup: ObjectDB Instances still exist!
     At: core/object.cpp:1990
ERROR: clear: Resources Still in use at Exit!
   At: core/resource.cpp:422

Also in this case, exporting with debug off seems to work fine.

volzhs commented 6 years ago

@jahd2602 for me, exported apk with release works fine, but has above error with debug.