microsoft / jacdac

Device and service catalogs for Jacdac.
https://aka.ms/jacdac
Creative Commons Attribution 4.0 International
66 stars 25 forks source link

Fixed instances do not support generics #351

Closed pelikhan closed 3 years ago

pelikhan commented 3 years ago

It seems that generics break the fixedInstance resolution chain. We are using a generic SensorClient class in pxt-jacdac and loosing the base "connection" event. So either we need to fix PXT or change pxt-jacdac.

repro: https://makecode.microbit.org/_fAA0oz9LaAPy

// Fixed instance do not support generics
namespace bug {
    //% fixedInstances
    class Base {
        constructor() {

        }
        //% block="%base foo"
        foo() {

        }
    }

    //% fixedInstance whenUsed
    const base = new Base()

    class Child extends Base {
        constructor() {
            super()
        }
    }

    //% fixedInstance whenUsed
    const child = new Child()

    class ChildT<T> extends Base {
        constructor() {
            super()
        }
    }

    //% fixedInstance whenUsed
    const childT = new ChildT<number>()

    class GrandChildT extends ChildT<number> {
        constructor() {
            super()
        }
    }

    //% fixedInstance whenUsed
    const grandChild = new GrandChildT()
 }
pelikhan commented 3 years ago

Removed generics.