Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Incompatible return types compile in Quark, generated code throws errors #31

Closed
janicedatawire opened this issue Oct 20, 2015 · 1 comment

Comments

@janicedatawire
Copy link
Contributor

Quark lets me return a value of the wrong type. However, the generated code complains in all three languages.

For example, I compiled this class:

    class ConversionFactors {
         float foo=1;
         Map<String,float> initializeConversion() {
             Map<String,float> lengthFactors = new Map<String,float>();  
             lengthFactors.__set__("meter",1);
             lengthFactors.__set__("centimeter",100);
             lengthFactors.__set__("foot",3.2808399); 
             lengthFactors.__set__("mile",0.000621371);
          lengthFactors.__set__("parsec",0.000000000000000032407557442396);
             lengthFactors.__set__("league",0.00020712330174427);
             return foo;
         }
    }

It compiled and generated code in all three languages. However, all three threw errors when I tried to use the code:

$ python wrongReturn.py
Traceback (most recent call last):
  File "wrongReturn.py", line 40, in <module>
    main()
  File "wrongReturn.py", line 11, in main
    (length2).value = (conversion).Convert(length1, length2)
  File "/Users/janicekarin/quark-examples/python/convert/__init__.py", line 47, in Convert
    (input).conversionFactor = (self.relativeLengths).get((input).label)
AttributeError: 'int' object has no attribute 'get'
$ node wrongReturn.js
/Users/janicekarin/quark-examples/javascript/node_modules/quark_runtime.js:31
        if (m.has(key)) {
              ^
TypeError: undefined is not a function
    at Object.map_get (/Users/janicekarin/quark-examples/javascript/node_modules/quark_runtime.js:31:15)
    at Conversion_Convert [as Convert] (/Users/janicekarin/quark-examples/javascript/convert/index.js:63:45)
    at main (/Users/janicekarin/quark-examples/javascript/wrongReturn.js:10:36)
    at Object.<anonymous> (/Users/janicekarin/quark-examples/javascript/wrongReturn.js:39:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
$ javac Functions.java
Functions.java:4: error: incompatible types: int cannot be converted to Double
        convert.Unit length2 = new convert.Unit("length", "foot", 0);
                                                                  ^
./convert/Unit.java:8: error: incompatible types: int cannot be converted to Double
    public Double value = (Double) (0);
                                   ^
./convert/Unit.java:9: error: incompatible types: int cannot be converted to Double
    public Double conversionFactor = (Double) (0);
                                              ^
./convert/Conversion.java:15: error: incompatible types: int cannot be converted to Double
                return (Double) (-(123456789));
                                ^
./convert/Conversion.java:18: error: incompatible types: int cannot be converted to Double
            return (Double) (-(987654321));
                            ^
./convert/ConversionFactors.java:4: error: incompatible types: int cannot be converted to Double
    public Double foo = (Double) (1);
                                 ^
./convert/ConversionFactors.java:7: error: no suitable method found for put(String,int)
        (lengthFactors).put(("meter"), (1));
                       ^
    method Map.put(String,Double) is not applicable
      (argument mismatch; int cannot be converted to Double)
    method AbstractMap.put(String,Double) is not applicable
      (argument mismatch; int cannot be converted to Double)
    method HashMap.put(String,Double) is not applicable
      (argument mismatch; int cannot be converted to Double)
./convert/ConversionFactors.java:8: error: no suitable method found for put(String,int)
        (lengthFactors).put(("centimeter"), (100));
                       ^
    method Map.put(String,Double) is not applicable
      (argument mismatch; int cannot be converted to Double)
    method AbstractMap.put(String,Double) is not applicable
      (argument mismatch; int cannot be converted to Double)
    method HashMap.put(String,Double) is not applicable
      (argument mismatch; int cannot be converted to Double)
./convert/ConversionFactors.java:13: error: incompatible types: Double cannot be converted to HashMap<String,Double>
        return (java.util.HashMap<String,Double>) (foo);
                                                  ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
9 errors
@rhs
Copy link
Contributor

rhs commented Nov 16, 2015

This is fixed now.

@rhs rhs closed this as completed Nov 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants