wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
225 stars 30 forks source link

Compiletime bug #901

Closed netVoix closed 3 years ago

netVoix commented 4 years ago

Got compiletime error when trying to use next construction. ---declaration---

interface Setter<T>
      function run(T data)
public class UDERealField
        private Setter<real> setter
        private var baseVal = 0.
        private var bonusVal = 0.
        private var additional = 0.

       construct(Setter<real> valSetter)
            setter = valSetter

        function setBase(real data)
            baseVal = data
            setter.run(baseVal + bonusVal + additional)
        ...
public class UnitDefinitionExtended extends UnitDefinition
        ...
        var regenerationRate = new UDERealField(d -> this.setHitPointsRegenerationRate(d))

---use---

public function UnitDefinitionExtended.setSCUnitParams()
        ...
        this.regenerationRate.setBase(3.0)

---error---

Error in File UnitObjEditing.wurst line 493:
 You encountered a bug in the interpreter: java.lang.Error: java.lang.ClassCastException: de.peeeq.wurstscript.intermediatelang.ILconstInt cannot be cast to de.peeeq.wurstscript.intermediatelang.ILconstString
  at C:\Users\voix\Desktop\sc\_build\dependencies\WurstStdlib2\wurst\objediting\UnitObjEditing.wurst line 493
Error in File Bladedancer.wurst line 8:
 ... when calling bladedancer() in Bladedancer.wurst:8
Error in File Bladedancer.wurst line 6:
 ... when calling createSCUnitMelee(1851942252, 1851942252) in Bladedancer.wurst:6
Error in File UDEFabric.wurst line 6:
 ... when calling UnitDefinitionExtended_setSCMeleeUnitParams(UnitDefinitionExtended177_470) in UDEFabric.wurst:6
Error in File UDEUnitHelpers.wurst line 32:
 ... when calling UnitDefinitionExtended_setSCUnitParams(UnitDefinitionExtended177_470) in UDEUnitHelpers.wurst:32
Error in File UDEUnitHelpers.wurst line 28:
 ... when calling UDERealField_setBase(UDERealField180_486, 3.0) in UDEUnitHelpers.wurst:28
Error in File UDEField.wurst line 46:
 ... when calling run_wrapper(Setter_UnitDefinitionExtended_UDE741_485, 3000) in UDEField.wurst:46
Error in File UDE.wurst line 18:
 ... when calling run_UnitDefinitionExtended_UDE(Setter_UnitDefinitionExtended_UDE741_485, 3.0) in UDE.wurst:18
Error in File UDE.wurst line 18:
 ... when calling UnitOrBuildingOrHeroDefinition_setHitPointsRegenerationRate(Setter_UnitDefinitionExtended_UDE741_485, 3.0) in UDE.wurst:18
There were some problem while running compiletime expressions and functions.

When i did like this everything works fine. Why?

public class UnitDefinitionExtended extends UnitDefinition

    UDEIntField defense 
    UDEIntField hitPoints
    UDEIntField attackDamage
    UDERealField attackCooldownTime 
    UDEIntField stockReplenishInterval 
    UDEIntField goldCost
    UDEIntField mana 
    UDERealField regenerationRate

    construct(int newId, int origId)
        super(newId, origId)
        defense = new UDEIntField(d -> this.setDefenseBase(d))
        hitPoints = new UDEIntField(d -> this.setHitPointsMaximumBase(d))
        attackDamage = new UDEIntField(d -> this.setAttackDamageBase(d))
        attackCooldownTime = new UDERealField(d -> this.setAttackCooldownTime(d))
        stockReplenishInterval = new UDEIntField(d -> this.setStockReplenishInterval(d))
        goldCost = new UDEIntField(d -> this.setGoldCost(d))
        mana = new UDEIntField(d -> this.setMana(d))
        regenerationRate = new UDERealField(d -> this.setHitPointsRegenerationRate(d))
peq commented 4 years ago

I was not able to reproduce the problem on my machine. Can you share a complete example (e.g. link to Git revision)?

I guess it is a problem with generics and native types.

You can try to use template generics by adding a colon to the type parameter:

interface Setter<T:>